From 488e9638b71b8b9cdb3055835815d77720eae06b Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Fri, 8 Oct 2021 09:13:08 +0900 Subject: Imported Upstream version 3.10.0 --- Source/.gitattributes | 2 - Source/CMakeLists.txt | 68 +- Source/CMakeVersion.cmake | 4 +- Source/CPack/IFW/cmCPackIFWCommon.cxx | 4 +- Source/CPack/IFW/cmCPackIFWGenerator.cxx | 100 +- Source/CPack/IFW/cmCPackIFWGenerator.h | 30 +- Source/CPack/IFW/cmCPackIFWInstaller.cxx | 16 +- Source/CPack/IFW/cmCPackIFWPackage.cxx | 136 +- Source/CPack/IFW/cmCPackIFWPackage.h | 6 + Source/CPack/IFW/cmCPackIFWRepository.cxx | 27 +- Source/CPack/OSXScriptLauncher.cxx | 8 +- Source/CPack/WiX/cmCPackWIXGenerator.cxx | 51 +- Source/CPack/WiX/cmWIXAccessControlList.cxx | 8 +- Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx | 12 +- Source/CPack/WiX/cmWIXPatch.cxx | 23 +- Source/CPack/WiX/cmWIXPatchParser.cxx | 6 +- Source/CPack/WiX/cmWIXRichTextFormatWriter.h | 2 +- Source/CPack/WiX/cmWIXShortcut.cxx | 16 +- Source/CPack/WiX/cmWIXSourceWriter.cxx | 4 +- Source/CPack/cmCPack7zGenerator.h | 6 +- Source/CPack/cmCPackArchiveGenerator.cxx | 64 +- Source/CPack/cmCPackArchiveGenerator.h | 12 +- Source/CPack/cmCPackBundleGenerator.cxx | 9 +- Source/CPack/cmCPackBundleGenerator.h | 12 +- Source/CPack/cmCPackComponentGroup.cxx | 6 +- Source/CPack/cmCPackComponentGroup.h | 6 +- Source/CPack/cmCPackCygwinBinaryGenerator.h | 2 +- Source/CPack/cmCPackCygwinSourceGenerator.h | 2 +- Source/CPack/cmCPackDebGenerator.cxx | 397 +-- Source/CPack/cmCPackDebGenerator.h | 14 +- Source/CPack/cmCPackDragNDropGenerator.cxx | 62 +- Source/CPack/cmCPackDragNDropGenerator.h | 20 +- Source/CPack/cmCPackFreeBSDGenerator.cxx | 359 +++ Source/CPack/cmCPackFreeBSDGenerator.h | 37 + Source/CPack/cmCPackGenerator.cxx | 168 +- Source/CPack/cmCPackGenerator.h | 6 +- Source/CPack/cmCPackGeneratorFactory.cxx | 24 +- Source/CPack/cmCPackLog.cxx | 9 +- Source/CPack/cmCPackNSISGenerator.cxx | 141 +- Source/CPack/cmCPackNSISGenerator.h | 20 +- Source/CPack/cmCPackOSXX11Generator.cxx | 10 +- Source/CPack/cmCPackOSXX11Generator.h | 12 +- Source/CPack/cmCPackPKGGenerator.cxx | 6 +- Source/CPack/cmCPackPKGGenerator.h | 10 +- Source/CPack/cmCPackPackageMakerGenerator.cxx | 15 +- Source/CPack/cmCPackPackageMakerGenerator.h | 12 +- Source/CPack/cmCPackProductBuildGenerator.cxx | 12 +- Source/CPack/cmCPackProductBuildGenerator.h | 10 +- Source/CPack/cmCPackRPMGenerator.cxx | 8 +- Source/CPack/cmCPackRPMGenerator.h | 14 +- Source/CPack/cmCPackSTGZGenerator.cxx | 6 +- Source/CPack/cmCPackSTGZGenerator.h | 12 +- Source/CPack/cmCPackTGZGenerator.h | 6 +- Source/CPack/cmCPackTXZGenerator.h | 6 +- Source/CPack/cmCPackTarBZip2Generator.h | 6 +- Source/CPack/cmCPackTarCompressGenerator.h | 6 +- Source/CPack/cmCPackZIPGenerator.h | 6 +- Source/CPack/cpack.cxx | 88 +- Source/CTest/cmCTestBZR.cxx | 46 +- Source/CTest/cmCTestBZR.h | 14 +- Source/CTest/cmCTestBatchTestHandler.cxx | 12 +- Source/CTest/cmCTestBatchTestHandler.h | 6 +- Source/CTest/cmCTestBuildAndTestHandler.cxx | 49 +- Source/CTest/cmCTestBuildAndTestHandler.h | 12 +- Source/CTest/cmCTestBuildCommand.cxx | 24 +- Source/CTest/cmCTestBuildCommand.h | 12 +- Source/CTest/cmCTestBuildHandler.cxx | 143 +- Source/CTest/cmCTestBuildHandler.h | 8 +- Source/CTest/cmCTestCVS.cxx | 32 +- Source/CTest/cmCTestCVS.h | 8 +- Source/CTest/cmCTestCommand.h | 4 +- Source/CTest/cmCTestConfigureCommand.cxx | 29 +- Source/CTest/cmCTestConfigureCommand.h | 8 +- Source/CTest/cmCTestConfigureHandler.cxx | 1 + Source/CTest/cmCTestConfigureHandler.h | 6 +- Source/CTest/cmCTestCoverageCommand.cxx | 2 +- Source/CTest/cmCTestCoverageCommand.h | 12 +- Source/CTest/cmCTestCoverageHandler.cxx | 266 +- Source/CTest/cmCTestCoverageHandler.h | 12 +- Source/CTest/cmCTestCurl.cxx | 45 +- Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h | 6 +- Source/CTest/cmCTestGIT.cxx | 74 +- Source/CTest/cmCTestGIT.h | 14 +- Source/CTest/cmCTestGenericHandler.cxx | 11 +- Source/CTest/cmCTestGlobalVC.cxx | 19 +- Source/CTest/cmCTestGlobalVC.h | 6 +- Source/CTest/cmCTestHG.cxx | 55 +- Source/CTest/cmCTestHG.h | 14 +- Source/CTest/cmCTestHandlerCommand.cxx | 11 +- Source/CTest/cmCTestHandlerCommand.h | 4 +- Source/CTest/cmCTestLaunch.cxx | 48 +- Source/CTest/cmCTestMemCheckCommand.cxx | 2 +- Source/CTest/cmCTestMemCheckCommand.h | 8 +- Source/CTest/cmCTestMemCheckHandler.cxx | 109 +- Source/CTest/cmCTestMemCheckHandler.h | 15 +- Source/CTest/cmCTestMultiProcessHandler.cxx | 170 +- Source/CTest/cmCTestP4.cxx | 40 +- Source/CTest/cmCTestP4.h | 14 +- Source/CTest/cmCTestReadCustomFilesCommand.cxx | 5 +- Source/CTest/cmCTestReadCustomFilesCommand.h | 6 +- Source/CTest/cmCTestRunScriptCommand.h | 6 +- Source/CTest/cmCTestRunTest.cxx | 88 +- Source/CTest/cmCTestSVN.cxx | 49 +- Source/CTest/cmCTestSVN.h | 18 +- Source/CTest/cmCTestScriptHandler.cxx | 77 +- Source/CTest/cmCTestScriptHandler.h | 8 +- Source/CTest/cmCTestSleepCommand.h | 6 +- Source/CTest/cmCTestStartCommand.cxx | 6 +- Source/CTest/cmCTestStartCommand.h | 6 +- Source/CTest/cmCTestSubmitCommand.cxx | 4 +- Source/CTest/cmCTestSubmitCommand.h | 14 +- Source/CTest/cmCTestSubmitHandler.cxx | 162 +- Source/CTest/cmCTestSubmitHandler.h | 8 +- Source/CTest/cmCTestTestCommand.cxx | 8 +- Source/CTest/cmCTestTestCommand.h | 8 +- Source/CTest/cmCTestTestHandler.cxx | 626 ++-- Source/CTest/cmCTestTestHandler.h | 33 +- Source/CTest/cmCTestUpdateCommand.cxx | 4 +- Source/CTest/cmCTestUpdateCommand.h | 8 +- Source/CTest/cmCTestUpdateHandler.cxx | 23 +- Source/CTest/cmCTestUpdateHandler.h | 6 +- Source/CTest/cmCTestUploadCommand.cxx | 2 +- Source/CTest/cmCTestUploadCommand.h | 12 +- Source/CTest/cmCTestUploadHandler.cxx | 10 +- Source/CTest/cmCTestUploadHandler.h | 8 +- Source/CTest/cmCTestVC.cxx | 10 +- Source/CTest/cmCTestVC.h | 10 +- Source/CTest/cmParseBlanketJSCoverage.cxx | 8 +- Source/CTest/cmParseCacheCoverage.cxx | 12 +- Source/CTest/cmParseCacheCoverage.h | 4 +- Source/CTest/cmParseCoberturaCoverage.cxx | 25 +- Source/CTest/cmParseDelphiCoverage.cxx | 3 +- Source/CTest/cmParseGTMCoverage.cxx | 6 +- Source/CTest/cmParseGTMCoverage.h | 4 +- Source/CTest/cmParseJacocoCoverage.cxx | 23 +- Source/CTest/cmParseMumpsCoverage.cxx | 16 +- Source/CTest/cmProcess.cxx | 15 +- Source/CTest/cmProcess.h | 1 + Source/Checks/cm_cxx_attribute_fallthrough.cxx | 2 +- Source/Checks/cm_cxx_auto_ptr.cxx | 18 - Source/Checks/cm_cxx_eq_delete.cxx | 14 - Source/Checks/cm_cxx_fallthrough.cxx | 2 +- Source/Checks/cm_cxx_features.cmake | 11 +- Source/Checks/cm_cxx_gnu_fallthrough.cxx | 2 +- Source/Checks/cm_cxx_nullptr.cxx | 14 - Source/Checks/cm_cxx_override.cxx | 24 - Source/Checks/cm_cxx_unordered_map.cxx | 7 - Source/Checks/cm_cxx_unordered_set.cxx | 7 - Source/CursesDialog/CMakeLists.txt | 4 - Source/CursesDialog/ccmake.cxx | 28 +- Source/CursesDialog/cmCursesBoolWidget.h | 4 +- .../CursesDialog/cmCursesCacheEntryComposite.cxx | 11 +- Source/CursesDialog/cmCursesCacheEntryComposite.h | 2 +- Source/CursesDialog/cmCursesDummyWidget.h | 4 +- Source/CursesDialog/cmCursesFilePathWidget.h | 2 +- Source/CursesDialog/cmCursesForm.cxx | 4 +- Source/CursesDialog/cmCursesForm.h | 2 +- Source/CursesDialog/cmCursesLabelWidget.h | 6 +- Source/CursesDialog/cmCursesLongMessageForm.cxx | 8 +- Source/CursesDialog/cmCursesLongMessageForm.h | 10 +- Source/CursesDialog/cmCursesMainForm.cxx | 87 +- Source/CursesDialog/cmCursesMainForm.h | 12 +- Source/CursesDialog/cmCursesOptionsWidget.cxx | 5 +- Source/CursesDialog/cmCursesOptionsWidget.h | 4 +- Source/CursesDialog/cmCursesPathWidget.h | 8 +- Source/CursesDialog/cmCursesStandardIncludes.h | 2 +- Source/CursesDialog/cmCursesStringWidget.cxx | 6 +- Source/CursesDialog/cmCursesStringWidget.h | 8 +- Source/CursesDialog/cmCursesWidget.cxx | 2 +- Source/CursesDialog/cmCursesWidget.h | 2 +- Source/CursesDialog/form/.gitattributes | 1 - Source/CursesDialog/form/CMakeLists.txt | 17 +- Source/LexerParser/.gitattributes | 17 - Source/LexerParser/cmCommandArgumentLexer.cxx | 671 +++-- Source/LexerParser/cmCommandArgumentLexer.h | 441 ++- Source/LexerParser/cmCommandArgumentLexer.in.l | 11 +- Source/LexerParser/cmDependsJavaLexer.cxx | 767 ++--- Source/LexerParser/cmDependsJavaLexer.h | 441 ++- Source/LexerParser/cmDependsJavaLexer.in.l | 11 +- Source/LexerParser/cmExprLexer.cxx | 670 +++-- Source/LexerParser/cmExprLexer.h | 441 ++- Source/LexerParser/cmExprLexer.in.l | 11 +- Source/LexerParser/cmFortranLexer.cxx | 995 ++++--- Source/LexerParser/cmFortranLexer.h | 441 ++- Source/LexerParser/cmFortranLexer.in.l | 11 +- Source/LexerParser/cmListFileLexer.c | 887 +++--- Source/LexerParser/cmListFileLexer.in.l | 28 +- Source/QtDialog/CMakeLists.txt | 8 +- Source/QtDialog/CMakeSetup.cxx | 23 +- Source/QtDialog/CMakeSetupDialog.cxx | 6 +- Source/QtDialog/CMakeSetupDialog.h | 2 +- Source/QtDialog/Compilers.h | 4 +- Source/QtDialog/FirstConfigure.cxx | 2 +- Source/QtDialog/QCMake.h | 4 +- Source/QtDialog/QCMakeCacheView.cxx | 8 +- Source/QtDialog/QCMakeWidgets.cxx | 6 +- Source/QtDialog/QCMakeWidgets.h | 7 +- Source/bindexplib.cxx | 12 +- Source/bindexplib.h | 2 +- Source/cmAddCompileOptionsCommand.cxx | 5 +- Source/cmAddCompileOptionsCommand.h | 6 +- Source/cmAddCustomCommandCommand.cxx | 17 +- Source/cmAddCustomCommandCommand.h | 6 +- Source/cmAddCustomTargetCommand.cxx | 2 +- Source/cmAddCustomTargetCommand.h | 6 +- Source/cmAddDefinitionsCommand.cxx | 5 +- Source/cmAddDefinitionsCommand.h | 6 +- Source/cmAddDependenciesCommand.h | 6 +- Source/cmAddExecutableCommand.h | 6 +- Source/cmAddLibraryCommand.h | 6 +- Source/cmAddSubDirectoryCommand.h | 6 +- Source/cmAddTestCommand.h | 6 +- Source/cmAlgorithms.h | 24 +- Source/cmArchiveWrite.cxx | 6 +- Source/cmArchiveWrite.h | 4 +- Source/cmAuxSourceDirectoryCommand.h | 6 +- Source/cmBreakCommand.h | 6 +- Source/cmBuildCommand.h | 6 +- Source/cmBuildNameCommand.cxx | 2 +- Source/cmBuildNameCommand.h | 6 +- Source/cmCLocaleEnvironmentScope.cxx | 5 +- Source/cmCLocaleEnvironmentScope.h | 2 +- Source/cmCMakeHostSystemInformationCommand.cxx | 49 + Source/cmCMakeHostSystemInformationCommand.h | 6 +- Source/cmCMakeMinimumRequired.cxx | 10 +- Source/cmCMakeMinimumRequired.h | 6 +- Source/cmCMakePolicyCommand.h | 6 +- Source/cmCPackPropertiesGenerator.cxx | 15 +- Source/cmCPackPropertiesGenerator.h | 4 +- Source/cmCPluginAPI.cxx | 66 +- Source/cmCTest.cxx | 253 +- Source/cmCTest.h | 23 +- Source/cmCacheManager.cxx | 37 +- Source/cmCacheManager.h | 7 +- Source/cmCallVisualStudioMacro.h | 2 +- Source/cmCommand.h | 4 +- Source/cmCommandArgumentParserHelper.cxx | 18 +- Source/cmCommandArgumentParserHelper.h | 2 +- Source/cmCommandArgumentsHelper.cxx | 74 +- Source/cmCommandArgumentsHelper.h | 28 +- Source/cmCommands.cxx | 34 +- Source/cmCommonTargetGenerator.cxx | 47 +- Source/cmCommonTargetGenerator.h | 4 +- Source/cmComputeComponentGraph.cxx | 10 +- Source/cmComputeLinkDepends.cxx | 97 +- Source/cmComputeLinkDepends.h | 2 +- Source/cmComputeLinkInformation.cxx | 131 +- Source/cmComputeLinkInformation.h | 4 +- Source/cmComputeTargetDepends.cxx | 103 +- Source/cmConditionEvaluator.cxx | 13 +- Source/cmConfigure.cmake.h.in | 32 +- Source/cmConfigureFileCommand.h | 6 +- Source/cmConnection.cxx | 168 ++ Source/cmConnection.h | 134 + Source/cmContinueCommand.h | 6 +- Source/cmCoreTryCompile.cxx | 60 +- Source/cmCreateTestSourceList.h | 6 +- Source/cmCryptoHash.cxx | 34 +- Source/cmCryptoHash.h | 7 +- Source/cmCurl.h | 4 +- Source/cmCustomCommand.cxx | 6 +- Source/cmCustomCommandGenerator.cxx | 69 +- Source/cmCustomCommandGenerator.h | 4 +- Source/cmDefinePropertyCommand.h | 6 +- Source/cmDefinitions.cxx | 30 +- Source/cmDefinitions.h | 4 +- Source/cmDepends.cxx | 20 +- Source/cmDepends.h | 4 +- Source/cmDependsC.cxx | 79 +- Source/cmDependsC.h | 6 +- Source/cmDependsFortran.cxx | 93 +- Source/cmDependsFortran.h | 8 +- Source/cmDependsJava.h | 8 +- Source/cmDependsJavaParserHelper.cxx | 56 +- Source/cmDisallowedCommand.h | 15 +- Source/cmDocumentation.cxx | 57 +- Source/cmDocumentation.h | 4 +- Source/cmDocumentationFormatter.cxx | 15 +- Source/cmDynamicLoader.cxx | 10 +- Source/cmDynamicLoader.h | 2 +- Source/cmELF.cxx | 59 +- Source/cmELF.h | 4 +- Source/cmEnableLanguageCommand.cxx | 7 +- Source/cmEnableLanguageCommand.h | 6 +- Source/cmEnableTestingCommand.h | 6 +- Source/cmExecProgramCommand.cxx | 22 +- Source/cmExecProgramCommand.h | 9 +- Source/cmExecuteProcessCommand.cxx | 71 +- Source/cmExecuteProcessCommand.h | 6 +- Source/cmExportBuildAndroidMKGenerator.cxx | 42 +- Source/cmExportBuildAndroidMKGenerator.h | 27 +- Source/cmExportBuildFileGenerator.cxx | 45 +- Source/cmExportBuildFileGenerator.h | 10 +- Source/cmExportCommand.cxx | 32 +- Source/cmExportCommand.h | 6 +- Source/cmExportFileGenerator.cxx | 123 +- Source/cmExportInstallAndroidMKGenerator.cxx | 5 +- Source/cmExportInstallAndroidMKGenerator.h | 41 +- Source/cmExportInstallFileGenerator.cxx | 55 +- Source/cmExportInstallFileGenerator.h | 12 +- Source/cmExportLibraryDependenciesCommand.cxx | 56 +- Source/cmExportLibraryDependenciesCommand.h | 10 +- Source/cmExportSet.cxx | 5 +- Source/cmExportTryCompileFileGenerator.cxx | 34 +- Source/cmExportTryCompileFileGenerator.h | 10 +- Source/cmExprParserHelper.cxx | 4 +- Source/cmExternalMakefileProjectGenerator.h | 2 +- Source/cmExtraCodeBlocksGenerator.cxx | 185 +- Source/cmExtraCodeBlocksGenerator.h | 4 +- Source/cmExtraCodeLiteGenerator.cxx | 102 +- Source/cmExtraCodeLiteGenerator.h | 4 +- Source/cmExtraEclipseCDT4Generator.cxx | 175 +- Source/cmExtraEclipseCDT4Generator.h | 8 +- Source/cmExtraKateGenerator.cxx | 56 +- Source/cmExtraKateGenerator.h | 4 +- Source/cmExtraSublimeTextGenerator.cxx | 62 +- Source/cmExtraSublimeTextGenerator.h | 6 +- Source/cmFLTKWrapUICommand.cxx | 4 +- Source/cmFLTKWrapUICommand.h | 10 +- Source/cmFileCommand.cxx | 214 +- Source/cmFileCommand.h | 6 +- Source/cmFileLock.cxx | 2 +- Source/cmFileLock.h | 2 +- Source/cmFileLockPool.cxx | 28 +- Source/cmFileLockPool.h | 2 +- Source/cmFileLockResult.cxx | 19 +- Source/cmFileMonitor.cxx | 37 +- Source/cmFileMonitor.h | 2 +- Source/cmFilePathChecksum.cxx | 51 +- Source/cmFilePathChecksum.h | 25 +- Source/cmFileTimeComparison.cxx | 29 +- Source/cmFindBase.cxx | 15 +- Source/cmFindCommon.cxx | 42 +- Source/cmFindCommon.h | 6 +- Source/cmFindFileCommand.h | 4 +- Source/cmFindLibraryCommand.cxx | 74 +- Source/cmFindLibraryCommand.h | 6 +- Source/cmFindPackageCommand.cxx | 176 +- Source/cmFindPackageCommand.h | 6 +- Source/cmFindPathCommand.cxx | 24 +- Source/cmFindPathCommand.h | 6 +- Source/cmFindProgramCommand.cxx | 44 +- Source/cmFindProgramCommand.h | 6 +- Source/cmForEachCommand.cxx | 13 +- Source/cmForEachCommand.h | 12 +- Source/cmFortranParser.h | 2 +- Source/cmFortranParserImpl.cxx | 14 +- Source/cmFunctionCommand.cxx | 12 +- Source/cmFunctionCommand.h | 12 +- Source/cmGeneratedFileStream.h | 4 +- Source/cmGeneratorExpression.cxx | 25 +- Source/cmGeneratorExpression.h | 23 +- Source/cmGeneratorExpressionContext.h | 2 +- Source/cmGeneratorExpressionDAGChecker.cxx | 2 +- Source/cmGeneratorExpressionDAGChecker.h | 6 +- Source/cmGeneratorExpressionEvaluationFile.cxx | 110 +- Source/cmGeneratorExpressionEvaluationFile.h | 21 +- Source/cmGeneratorExpressionEvaluator.cxx | 12 +- Source/cmGeneratorExpressionEvaluator.h | 18 +- Source/cmGeneratorExpressionNode.cxx | 494 ++-- Source/cmGeneratorExpressionParser.cxx | 2 +- Source/cmGeneratorTarget.cxx | 698 ++--- Source/cmGeneratorTarget.h | 13 +- Source/cmGetCMakePropertyCommand.cxx | 2 +- Source/cmGetCMakePropertyCommand.h | 6 +- Source/cmGetDirectoryPropertyCommand.cxx | 2 +- Source/cmGetDirectoryPropertyCommand.h | 6 +- Source/cmGetFilenameComponentCommand.cxx | 25 +- Source/cmGetFilenameComponentCommand.h | 6 +- Source/cmGetPropertyCommand.cxx | 8 +- Source/cmGetPropertyCommand.h | 6 +- Source/cmGetSourceFilePropertyCommand.cxx | 2 +- Source/cmGetSourceFilePropertyCommand.h | 6 +- Source/cmGetTargetPropertyCommand.cxx | 2 +- Source/cmGetTargetPropertyCommand.h | 6 +- Source/cmGetTestPropertyCommand.cxx | 2 +- Source/cmGetTestPropertyCommand.h | 6 +- Source/cmGhsMultiGpj.h | 2 +- Source/cmGhsMultiTargetGenerator.cxx | 6 +- Source/cmGlobalCommonGenerator.h | 4 +- Source/cmGlobalGenerator.cxx | 494 ++-- Source/cmGlobalGenerator.h | 49 +- Source/cmGlobalGeneratorFactory.h | 14 +- Source/cmGlobalGhsMultiGenerator.cxx | 6 +- Source/cmGlobalGhsMultiGenerator.h | 4 +- Source/cmGlobalKdevelopGenerator.cxx | 95 +- Source/cmGlobalKdevelopGenerator.h | 4 +- Source/cmGlobalNMakeMakefileGenerator.h | 2 +- Source/cmGlobalNinjaGenerator.cxx | 378 ++- Source/cmGlobalNinjaGenerator.h | 70 +- Source/cmGlobalUnixMakefileGenerator3.cxx | 176 +- Source/cmGlobalUnixMakefileGenerator3.h | 54 +- Source/cmGlobalVisualStudio10Generator.cxx | 39 +- Source/cmGlobalVisualStudio10Generator.h | 2 +- Source/cmGlobalVisualStudio11Generator.cxx | 10 +- Source/cmGlobalVisualStudio11Generator.h | 2 +- Source/cmGlobalVisualStudio12Generator.cxx | 10 +- Source/cmGlobalVisualStudio12Generator.h | 4 +- Source/cmGlobalVisualStudio14Generator.cxx | 17 +- Source/cmGlobalVisualStudio14Generator.h | 2 +- Source/cmGlobalVisualStudio15Generator.cxx | 4 +- Source/cmGlobalVisualStudio15Generator.h | 8 +- Source/cmGlobalVisualStudio7Generator.cxx | 12 +- Source/cmGlobalVisualStudio7Generator.h | 4 +- Source/cmGlobalVisualStudio8Generator.cxx | 16 +- Source/cmGlobalVisualStudio9Generator.cxx | 10 +- Source/cmGlobalVisualStudioGenerator.cxx | 20 +- Source/cmGlobalVisualStudioGenerator.h | 4 +- Source/cmGlobalWatcomWMakeGenerator.h | 10 +- Source/cmGlobalXCodeGenerator.cxx | 529 ++-- Source/cmGlobalXCodeGenerator.h | 47 +- Source/cmGraphVizWriter.cxx | 229 +- Source/cmHexFileConverter.cxx | 13 +- Source/cmHexFileConverter.h | 2 + Source/cmIDEOptions.h | 2 +- Source/cmIfCommand.cxx | 44 +- Source/cmIfCommand.h | 14 +- Source/cmIncludeCommand.cxx | 2 +- Source/cmIncludeCommand.h | 6 +- Source/cmIncludeDirectoryCommand.cxx | 2 +- Source/cmIncludeDirectoryCommand.h | 6 +- Source/cmIncludeExternalMSProjectCommand.cxx | 5 +- Source/cmIncludeExternalMSProjectCommand.h | 9 +- Source/cmIncludeGuardCommand.cxx | 108 + Source/cmIncludeGuardCommand.h | 37 + Source/cmIncludeRegularExpressionCommand.h | 9 +- Source/cmInstallCommand.cxx | 114 +- Source/cmInstallCommand.h | 6 +- Source/cmInstallCommandArguments.cxx | 38 +- Source/cmInstallDirectoryGenerator.cxx | 19 +- Source/cmInstallDirectoryGenerator.h | 10 +- Source/cmInstallExportAndroidMKGenerator.cxx | 8 +- Source/cmInstallExportGenerator.cxx | 33 +- Source/cmInstallExportGenerator.h | 12 +- Source/cmInstallFilesCommand.h | 10 +- Source/cmInstallFilesGenerator.cxx | 14 +- Source/cmInstallFilesGenerator.h | 10 +- Source/cmInstallGenerator.cxx | 9 +- Source/cmInstallGenerator.h | 12 +- Source/cmInstallProgramsCommand.h | 10 +- Source/cmInstallScriptGenerator.cxx | 2 +- Source/cmInstallScriptGenerator.h | 6 +- Source/cmInstallTargetGenerator.cxx | 43 +- Source/cmInstallTargetGenerator.h | 10 +- Source/cmInstallTargetsCommand.cxx | 2 +- Source/cmInstallTargetsCommand.h | 6 +- Source/cmInstalledFile.cxx | 13 +- Source/cmInstalledFile.h | 4 +- Source/cmLinkDirectoriesCommand.cxx | 5 +- Source/cmLinkDirectoriesCommand.h | 6 +- Source/cmLinkItem.h | 6 +- Source/cmLinkLibrariesCommand.h | 6 +- Source/cmLinkLineComputer.cxx | 28 +- Source/cmLinkLineComputer.h | 2 +- Source/cmLinkLineDeviceComputer.cxx | 18 +- Source/cmLinkLineDeviceComputer.h | 12 +- Source/cmLinkedTree.h | 4 +- Source/cmListCommand.cxx | 12 +- Source/cmListCommand.h | 6 +- Source/cmListFileCache.cxx | 9 +- Source/cmLoadCacheCommand.cxx | 25 +- Source/cmLoadCacheCommand.h | 6 +- Source/cmLoadCommandCommand.cxx | 40 +- Source/cmLoadCommandCommand.h | 6 +- Source/cmLocalCommonGenerator.cxx | 7 +- Source/cmLocalCommonGenerator.h | 6 +- Source/cmLocalGenerator.cxx | 364 +-- Source/cmLocalGenerator.h | 15 +- Source/cmLocalGhsMultiGenerator.cxx | 4 +- Source/cmLocalNinjaGenerator.cxx | 48 +- Source/cmLocalNinjaGenerator.h | 18 +- Source/cmLocalUnixMakefileGenerator3.cxx | 260 +- Source/cmLocalUnixMakefileGenerator3.h | 32 +- Source/cmLocalVisualStudio10Generator.cxx | 11 +- Source/cmLocalVisualStudio10Generator.h | 2 +- Source/cmLocalVisualStudio7Generator.cxx | 39 +- Source/cmLocalVisualStudio7Generator.h | 2 +- Source/cmLocalVisualStudioGenerator.cxx | 16 +- Source/cmLocalVisualStudioGenerator.h | 10 +- Source/cmLocalXCodeGenerator.cxx | 22 +- Source/cmLocalXCodeGenerator.h | 16 +- Source/cmLocale.h | 4 +- Source/cmMSVC60LinkLineComputer.h | 5 +- Source/cmMachO.cxx | 13 +- Source/cmMachO.h | 2 +- Source/cmMacroCommand.cxx | 28 +- Source/cmMacroCommand.h | 12 +- Source/cmMakeDirectoryCommand.h | 6 +- Source/cmMakefile.cxx | 417 ++- Source/cmMakefile.h | 110 +- Source/cmMakefileExecutableTargetGenerator.cxx | 38 +- Source/cmMakefileExecutableTargetGenerator.h | 6 +- Source/cmMakefileLibraryTargetGenerator.cxx | 58 +- Source/cmMakefileLibraryTargetGenerator.h | 6 +- Source/cmMakefileTargetGenerator.cxx | 250 +- Source/cmMakefileTargetGenerator.h | 10 +- Source/cmMakefileUtilityTargetGenerator.cxx | 2 +- Source/cmMakefileUtilityTargetGenerator.h | 6 +- Source/cmMarkAsAdvancedCommand.cxx | 2 +- Source/cmMarkAsAdvancedCommand.h | 6 +- Source/cmMathCommand.h | 6 +- Source/cmMessageCommand.h | 6 +- Source/cmNinjaLinkLineComputer.h | 5 +- Source/cmNinjaNormalTargetGenerator.cxx | 107 +- Source/cmNinjaNormalTargetGenerator.h | 6 +- Source/cmNinjaTargetGenerator.cxx | 129 +- Source/cmNinjaTargetGenerator.h | 10 +- Source/cmNinjaTypes.h | 2 + Source/cmNinjaUtilityTargetGenerator.cxx | 19 +- Source/cmNinjaUtilityTargetGenerator.h | 6 +- Source/cmOSXBundleGenerator.cxx | 11 +- Source/cmOptionCommand.h | 6 +- Source/cmOrderDirectories.cxx | 63 +- Source/cmOrderDirectories.h | 4 +- Source/cmOutputConverter.cxx | 9 +- Source/cmOutputRequiredFilesCommand.cxx | 76 +- Source/cmOutputRequiredFilesCommand.h | 6 +- Source/cmParseArgumentsCommand.cxx | 88 +- Source/cmParseArgumentsCommand.h | 6 +- Source/cmPathLabel.cxx | 6 +- Source/cmPipeConnection.cxx | 82 + Source/cmPipeConnection.h | 28 + Source/cmPolicies.cxx | 20 +- Source/cmPolicies.h | 9 +- Source/cmProcessTools.cxx | 20 +- Source/cmProcessTools.h | 10 +- Source/cmProjectCommand.cxx | 9 +- Source/cmProjectCommand.h | 6 +- Source/cmProperty.cxx | 4 +- Source/cmPropertyMap.cxx | 8 +- Source/cmQTWrapCPPCommand.cxx | 2 +- Source/cmQTWrapCPPCommand.h | 6 +- Source/cmQTWrapUICommand.cxx | 4 +- Source/cmQTWrapUICommand.h | 6 +- Source/cmQtAutoGen.cxx | 374 +++ Source/cmQtAutoGen.h | 72 + Source/cmQtAutoGenDigest.h | 64 + Source/cmQtAutoGeneratorCommon.cxx | 216 -- Source/cmQtAutoGeneratorCommon.h | 39 - Source/cmQtAutoGeneratorInitializer.cxx | 1594 ++++++----- Source/cmQtAutoGeneratorInitializer.h | 14 +- Source/cmQtAutoGenerators.cxx | 2993 +++++++++++--------- Source/cmQtAutoGenerators.h | 302 +- Source/cmRST.cxx | 14 +- Source/cmRemoveCommand.cxx | 8 +- Source/cmRemoveCommand.h | 6 +- Source/cmRemoveDefinitionsCommand.cxx | 5 +- Source/cmRemoveDefinitionsCommand.h | 6 +- Source/cmReturnCommand.h | 6 +- Source/cmScriptGenerator.cxx | 28 +- Source/cmScriptGenerator.h | 2 +- Source/cmSearchPath.cxx | 57 +- Source/cmSearchPath.h | 8 +- Source/cmSeparateArgumentsCommand.cxx | 24 +- Source/cmSeparateArgumentsCommand.h | 6 +- Source/cmServer.cxx | 287 +- Source/cmServer.h | 126 +- Source/cmServerConnection.cxx | 441 +-- Source/cmServerConnection.h | 106 +- Source/cmServerDictionary.h | 5 + Source/cmServerProtocol.cxx | 184 +- Source/cmServerProtocol.h | 9 +- Source/cmSetCommand.cxx | 6 +- Source/cmSetCommand.h | 6 +- Source/cmSetDirectoryPropertiesCommand.h | 9 +- Source/cmSetPropertyCommand.cxx | 47 +- Source/cmSetPropertyCommand.h | 6 +- Source/cmSetSourceFilesPropertiesCommand.h | 9 +- Source/cmSetTargetPropertiesCommand.h | 6 +- Source/cmSetTestsPropertiesCommand.h | 6 +- Source/cmSiteNameCommand.cxx | 4 +- Source/cmSiteNameCommand.h | 6 +- Source/cmSourceFile.cxx | 45 +- Source/cmSourceFile.h | 11 +- Source/cmSourceFileLocation.cxx | 19 +- Source/cmSourceFileLocation.h | 5 +- Source/cmSourceGroup.cxx | 6 +- Source/cmSourceGroup.h | 4 +- Source/cmSourceGroupCommand.cxx | 55 +- Source/cmSourceGroupCommand.h | 6 +- Source/cmState.cxx | 26 +- Source/cmStateDirectory.cxx | 17 +- Source/cmStateSnapshot.cxx | 2 +- Source/cmStateSnapshot.h | 2 +- Source/cmStringCommand.cxx | 45 +- Source/cmStringCommand.h | 7 +- Source/cmSubdirCommand.cxx | 19 +- Source/cmSubdirCommand.h | 6 +- Source/cmSubdirDependsCommand.h | 6 +- Source/cmSystemTools.cxx | 190 +- Source/cmSystemTools.h | 52 +- Source/cmTarget.cxx | 245 +- Source/cmTarget.h | 8 +- Source/cmTargetCompileDefinitionsCommand.cxx | 9 +- Source/cmTargetCompileDefinitionsCommand.h | 17 +- Source/cmTargetCompileFeaturesCommand.cxx | 5 +- Source/cmTargetCompileFeaturesCommand.h | 14 +- Source/cmTargetCompileOptionsCommand.h | 14 +- Source/cmTargetIncludeDirectoriesCommand.cxx | 22 +- Source/cmTargetIncludeDirectoriesCommand.h | 19 +- Source/cmTargetLinkLibrariesCommand.cxx | 15 +- Source/cmTargetLinkLibrariesCommand.h | 6 +- Source/cmTargetPropertyComputer.cxx | 15 +- Source/cmTargetPropertyComputer.h | 12 +- Source/cmTargetSourcesCommand.h | 14 +- Source/cmTestGenerator.cxx | 24 +- Source/cmTestGenerator.h | 14 +- Source/cmTimestamp.cxx | 9 +- Source/cmTryCompileCommand.h | 6 +- Source/cmTryRunCommand.cxx | 31 +- Source/cmTryRunCommand.h | 6 +- Source/cmUnexpectedCommand.h | 6 +- Source/cmUnsetCommand.cxx | 2 +- Source/cmUnsetCommand.h | 6 +- Source/cmUseMangledMesaCommand.cxx | 5 +- Source/cmUseMangledMesaCommand.h | 6 +- Source/cmUtilitySourceCommand.cxx | 4 +- Source/cmUtilitySourceCommand.h | 6 +- Source/cmVS10CLFlagTable.h | 3 +- Source/cmVS10CSharpFlagTable.h | 3 +- Source/cmVS10LinkFlagTable.h | 13 +- Source/cmVS11CLFlagTable.h | 3 +- Source/cmVS11CSharpFlagTable.h | 3 +- Source/cmVS11LinkFlagTable.h | 13 +- Source/cmVS12CLFlagTable.h | 3 +- Source/cmVS12CSharpFlagTable.h | 3 +- Source/cmVS12LinkFlagTable.h | 13 +- Source/cmVS140CLFlagTable.h | 3 +- Source/cmVS140CSharpFlagTable.h | 3 +- Source/cmVS140LinkFlagTable.h | 13 +- Source/cmVS141CLFlagTable.h | 4 +- Source/cmVS141CSharpFlagTable.h | 3 +- Source/cmVS141LinkFlagTable.h | 14 +- Source/cmVS14LibFlagTable.h | 1 + Source/cmVSSetupHelper.cxx | 62 +- Source/cmVSSetupHelper.h | 5 +- Source/cmVariableRequiresCommand.h | 6 +- Source/cmVariableWatch.cxx | 40 +- Source/cmVariableWatch.h | 14 +- Source/cmVariableWatchCommand.cxx | 6 +- Source/cmVariableWatchCommand.h | 10 +- Source/cmVisualStudio10TargetGenerator.cxx | 557 ++-- Source/cmVisualStudio10TargetGenerator.h | 20 +- Source/cmVisualStudio10ToolsetOptions.h | 2 +- Source/cmVisualStudioGeneratorOptions.cxx | 70 +- Source/cmVisualStudioGeneratorOptions.h | 4 +- Source/cmVisualStudioSlnData.h | 2 +- Source/cmVisualStudioSlnParser.cxx | 2 +- Source/cmVisualStudioSlnParser.h | 2 +- Source/cmVisualStudioWCEPlatformParser.cxx | 8 +- Source/cmVisualStudioWCEPlatformParser.h | 2 +- Source/cmWhileCommand.cxx | 19 +- Source/cmWhileCommand.h | 14 +- Source/cmWriteFileCommand.h | 6 +- Source/cmXCode21Object.cxx | 8 +- Source/cmXCode21Object.h | 2 +- Source/cmXCodeObject.cxx | 23 +- Source/cmXCodeObject.h | 12 +- Source/cmXCodeScheme.cxx | 71 +- Source/cmXCodeScheme.h | 25 +- Source/cmXMLParser.cxx | 14 +- Source/cmXMLWriter.h | 4 +- Source/cm_auto_ptr.hxx | 220 -- Source/cm_codecvt.hxx | 14 +- Source/cm_sys_stat.h | 5 + Source/cm_unordered_map.hxx | 25 - Source/cm_unordered_set.hxx | 25 - Source/cmake.cxx | 234 +- Source/cmake.h | 17 +- Source/cmakemain.cxx | 74 +- Source/cmakexbuild.cxx | 4 +- Source/cmcmd.cxx | 692 +++-- Source/cmcmd.h | 6 +- Source/ctest.cxx | 14 +- Source/kwsys/.gitattributes | 13 - Source/kwsys/CMakeLists.txt | 160 +- Source/kwsys/Directory.cxx | 4 +- Source/kwsys/ProcessUNIX.c | 3 +- Source/kwsys/RegularExpression.cxx | 5 - Source/kwsys/SystemTools.cxx | 184 +- Source/kwsys/SystemTools.hxx.in | 25 +- Source/kwsys/kwsysPlatformTestsCXX.cxx | 6 + Source/kwsys/testDirectory.cxx | 79 + Source/kwsys/testIOS.cxx | 139 - Source/kwsys/testSystemTools.cxx | 32 +- 685 files changed, 18523 insertions(+), 15568 deletions(-) delete mode 100644 Source/.gitattributes create mode 100644 Source/CPack/cmCPackFreeBSDGenerator.cxx create mode 100644 Source/CPack/cmCPackFreeBSDGenerator.h delete mode 100644 Source/Checks/cm_cxx_auto_ptr.cxx delete mode 100644 Source/Checks/cm_cxx_eq_delete.cxx delete mode 100644 Source/Checks/cm_cxx_nullptr.cxx delete mode 100644 Source/Checks/cm_cxx_override.cxx delete mode 100644 Source/Checks/cm_cxx_unordered_map.cxx delete mode 100644 Source/Checks/cm_cxx_unordered_set.cxx delete mode 100644 Source/CursesDialog/form/.gitattributes delete mode 100644 Source/LexerParser/.gitattributes create mode 100644 Source/cmConnection.cxx create mode 100644 Source/cmConnection.h create mode 100644 Source/cmIncludeGuardCommand.cxx create mode 100644 Source/cmIncludeGuardCommand.h create mode 100644 Source/cmPipeConnection.cxx create mode 100644 Source/cmPipeConnection.h create mode 100644 Source/cmQtAutoGen.cxx create mode 100644 Source/cmQtAutoGen.h create mode 100644 Source/cmQtAutoGenDigest.h delete mode 100644 Source/cmQtAutoGeneratorCommon.cxx delete mode 100644 Source/cmQtAutoGeneratorCommon.h delete mode 100644 Source/cm_auto_ptr.hxx delete mode 100644 Source/cm_unordered_map.hxx delete mode 100644 Source/cm_unordered_set.hxx delete mode 100644 Source/kwsys/.gitattributes create mode 100644 Source/kwsys/testDirectory.cxx delete mode 100644 Source/kwsys/testIOS.cxx (limited to 'Source') diff --git a/Source/.gitattributes b/Source/.gitattributes deleted file mode 100644 index 0f829a368..000000000 --- a/Source/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Do not format third-party sources. -/kwsys/** -format.clang-format diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 40403ca25..a4dd91860 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -307,8 +307,9 @@ set(SRCS cmPropertyDefinitionMap.h cmPropertyMap.cxx cmPropertyMap.h - cmQtAutoGeneratorCommon.cxx - cmQtAutoGeneratorCommon.h + cmQtAutoGen.cxx + cmQtAutoGen.h + cmQtAutoGenDigest.h cmQtAutoGeneratorInitializer.cxx cmQtAutoGeneratorInitializer.h cmQtAutoGenerators.cxx @@ -469,6 +470,8 @@ set(SRCS cmIncludeDirectoryCommand.h cmIncludeExternalMSProjectCommand.cxx cmIncludeExternalMSProjectCommand.h + cmIncludeGuardCommand.cxx + cmIncludeGuardCommand.h cmIncludeRegularExpressionCommand.cxx cmIncludeRegularExpressionCommand.h cmInstallCommand.cxx @@ -584,7 +587,6 @@ set(SRCS cmWriteFileCommand.cxx cmWriteFileCommand.h - cm_auto_ptr.hxx cm_get_date.h cm_get_date.c cm_utf8.h @@ -777,6 +779,8 @@ if(WIN32 AND NOT UNIX) target_link_libraries(CMakeLib rpcrt4 crypt32) endif() +target_compile_definitions(CMakeLib PUBLIC ${CLANG_TIDY_DEFINITIONS}) + # # CTestLib # @@ -874,6 +878,7 @@ set(CPACK_SRCS CPack/cmCPackTarCompressGenerator.cxx CPack/cmCPackZIPGenerator.cxx CPack/cmCPack7zGenerator.cxx + CPack/cmCPackDebGenerator.cxx ) # CPack IFW generator set(CPACK_SRCS ${CPACK_SRCS} @@ -896,11 +901,39 @@ 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" PATHS /usr/local) + 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) @@ -958,6 +991,11 @@ if(APPLE) "See CMakeFiles/CMakeError.log for details of the failure.") endif() 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) @@ -974,18 +1012,16 @@ 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 + 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}) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 5bd328ee3..8a93c36ca 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 6) +set(CMake_VERSION_MINOR 10) +set(CMake_VERSION_PATCH 0) #set(CMake_VERSION_RC 0) 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 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..825a88804 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -49,10 +49,22 @@ int cmCPackIFWGenerator::PackageFiles() ifwCmd += " -p " + this->toplevel + "/packages"; if (!this->PkgsDirsVector.empty()) { - for (std::vector::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 skiped, " + << "because this feature available only since " + << "QtIFW 3.1. Please update your QtIFW instance." + << std::endl); } } @@ -73,7 +85,7 @@ int cmCPackIFWGenerator::PackageFiles() int retVal = 1; cmCPackIFWLogger(OUTPUT, "- Generate repository" << std::endl); bool res = cmSystemTools::RunSingleCommand(ifwCmd.c_str(), &output, - &output, &retVal, CM_NULLPTR, + &output, &retVal, nullptr, this->GeneratorVerbose, 0); if (!res || retVal) { cmGeneratedFileStream ofs(ifwTmpFile.c_str()); @@ -121,10 +133,22 @@ int cmCPackIFWGenerator::PackageFiles() ifwCmd += " -p " + this->toplevel + "/packages"; if (!this->PkgsDirsVector.empty()) { - for (std::vector::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,13 +188,14 @@ 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, + &output, &retVal, nullptr, this->GeneratorVerbose, 0); if (!res || retVal) { cmGeneratedFileStream ofs(ifwTmpFile.c_str()); @@ -205,7 +230,7 @@ const char* cmCPackIFWGenerator::GetPackagingInstallPrefix() const char* cmCPackIFWGenerator::GetOutputExtension() { - return this->ExecutableSuffix.c_str(); + return this->OutputExtension.c_str(); } int cmCPackIFWGenerator::InitializeInternal() @@ -225,7 +250,7 @@ int cmCPackIFWGenerator::InitializeInternal() const char* BinCreatorStr = this->GetOption(BinCreatorOpt); if (!BinCreatorStr || cmSystemTools::IsNOTFOUND(BinCreatorStr)) { - this->BinCreator = ""; + this->BinCreator.clear(); } else { this->BinCreator = BinCreatorStr; } @@ -241,7 +266,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 +290,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 +313,8 @@ int cmCPackIFWGenerator::InitializeInternal() if (const char* RepoAllStr = this->GetOption("CPACK_IFW_REPOSITORIES_ALL")) { std::vector RepoAllVector; cmSystemTools::ExpandListArgument(RepoAllStr, RepoAllVector); - for (std::vector::iterator rit = RepoAllVector.begin(); - rit != RepoAllVector.end(); ++rit) { - this->GetRepository(*rit); + for (std::string const& r : RepoAllVector) { + this->GetRepository(r); } } @@ -305,16 +336,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 = this->cmCPackGenerator::GetOutputExtension(); + 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->OutputExtension = this->ExecutableSuffix; + } + if (this->OutputExtension.empty()) { + this->OutputExtension = this->cmCPackGenerator::GetOutputExtension(); } return this->Superclass::InitializeInternal(); @@ -520,7 +564,7 @@ cmCPackIFWPackage* cmCPackIFWGenerator::GetGroupPackage( { std::map::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 +572,7 @@ cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage( { std::map::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,7 +594,7 @@ cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository( } } else { this->Repositories.erase(repositoryName); - repository = CM_NULLPTR; + repository = nullptr; cmCPackIFWLogger(WARNING, "Invalid repository \"" << repositoryName << "\"" << " configuration. Repository will be skipped." diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.h b/Source/CPack/IFW/cmCPackIFWGenerator.h index 8348ceeec..919dd4678 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.h +++ b/Source/CPack/IFW/cmCPackIFWGenerator.h @@ -47,7 +47,7 @@ public: /** * Destruct IFW generator */ - ~cmCPackIFWGenerator() CM_OVERRIDE; + ~cmCPackIFWGenerator() override; protected: // cmCPackGenerator reimplementation @@ -56,18 +56,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 +79,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 +91,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 +143,12 @@ private: std::string BinCreator; std::string FrameworkVersion; std::string ExecutableSuffix; + std::string OutputExtension; bool OnlineOnly; bool ResolveDuplicateNames; std::vector PkgsDirsVector; + std::vector RepoDirsVector; }; #endif diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.cxx b/Source/CPack/IFW/cmCPackIFWInstaller.cxx index 288e924e5..422f5d5e7 100644 --- a/Source/CPack/IFW/cmCPackIFWInstaller.cxx +++ b/Source/CPack/IFW/cmCPackIFWInstaller.cxx @@ -262,7 +262,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,7 +270,7 @@ 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); @@ -284,7 +284,7 @@ protected: } } - void EndElement(const std::string& /*name*/) CM_OVERRIDE {} + void EndElement(const std::string& /*name*/) override {} }; void cmCPackIFWInstaller::GenerateInstallerFile() @@ -406,9 +406,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(); } @@ -492,9 +491,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/cmCPackIFWPackage.cxx b/Source/CPack/IFW/cmCPackIFWPackage.cxx index c5311c31c..d3ce15c86 100644 --- a/Source/CPack/IFW/cmCPackIFWPackage.cxx +++ b/Source/CPack/IFW/cmCPackIFWPackage.cxx @@ -92,7 +92,7 @@ std::string cmCPackIFWPackage::DependenceStruct::NameWithCompare() const //------------------------------------------------------ cmCPackIFWPackage --- cmCPackIFWPackage::cmCPackIFWPackage() - : Installer(CM_NULLPTR) + : Installer(nullptr) { } @@ -111,19 +111,19 @@ 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) @@ -203,10 +203,8 @@ int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component) // CMake dependencies if (!component->Dependencies.empty()) { - std::vector::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]); } } @@ -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::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 depsOn; cmSystemTools::ExpandListArgument(value, depsOn); - for (std::vector::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; } @@ -521,26 +536,22 @@ void cmCPackIFWPackage::GeneratePackageFile() xout.StartElement("Package"); // DisplayName (with translations) - for (std::map::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::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 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 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 compDepSet; - for (std::set::iterator ait = - this->AlienDependencies.begin(); - ait != this->AlienDependencies.end(); ++ait) { - compDepSet.insert(*(*ait)); + for (DependenceStruct* ad : this->AlienDependencies) { + compDepSet.insert(*ad); } - for (std::set::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 compAutoDepSet; - for (std::set::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::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 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..a01fc4ed3 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; } @@ -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..d3de02b47 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; } @@ -71,7 +71,7 @@ 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()); @@ -83,7 +83,7 @@ int main(int argc, char* argv[]) std::vector 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 +93,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..ba07d0863 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -89,9 +89,8 @@ 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); } AddCustomFlags("CPACK_WIX_CANDLE_EXTRA_FLAGS", command); @@ -113,9 +112,8 @@ bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles) command << " -nologo"; command << " -out " << QuotePath(packageFileNames.at(0)); - for (extension_set_t::const_iterator i = this->LightExtensions.begin(); - i != this->LightExtensions.end(); ++i) { - command << " -ext " << QuotePath(*i); + for (std::string const& ext : this->LightExtensions) { + command << " -ext " << QuotePath(ext); } const char* const cultures = GetOption("CPACK_WIX_CULTURES"); @@ -219,8 +217,8 @@ bool cmCPackWIXGenerator::InitializeWiXConfiguration() std::vector 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 +252,7 @@ bool cmCPackWIXGenerator::PackageFilesImpl() std::set 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); @@ -306,8 +302,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); } } @@ -345,9 +341,7 @@ void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile() std::string prefix = "CPACK_WIX_PROPERTY_"; std::vector 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()); @@ -503,16 +497,14 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() globalShortcuts.AddShortcutTypes(emittedShortcutTypes); } else { - for (std::map::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, @@ -623,19 +615,15 @@ bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate() bool cmCPackWIXGenerator::CreateFeatureHierarchy( cmWIXFeaturesSourceWriter& featureDefinitions) { - for (std::map::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::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); @@ -1135,9 +1123,8 @@ void cmCPackWIXGenerator::AddCustomFlags(std::string const& variableName, std::vector list; cmSystemTools::ExpandListArgument(variableContent, list); - for (std::vector::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/cmWIXAccessControlList.cxx b/Source/CPack/WiX/cmWIXAccessControlList.cxx index 744a93298..1603bf868 100644 --- a/Source/CPack/WiX/cmWIXAccessControlList.cxx +++ b/Source/CPack/WiX/cmWIXAccessControlList.cxx @@ -20,8 +20,8 @@ bool cmWIXAccessControlList::Apply() std::vector 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"); } 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::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::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/cmWIXPatch.cxx b/Source/CPack/WiX/cmWIXPatch.cxx index 287a644bb..dec95fb6e 100644 --- a/Source/CPack/WiX/cmWIXPatch.cxx +++ b/Source/CPack/WiX/cmWIXPatch.cxx @@ -29,10 +29,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 +40,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(*node), writer); @@ -63,10 +57,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 +69,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..e6aeed325 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]; 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 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& 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 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..dc730e00c 100644 --- a/Source/CPack/WiX/cmWIXSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx @@ -158,9 +158,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 += "<"; 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..641be3861 100644 --- a/Source/CPack/cmCPackArchiveGenerator.cxx +++ b/Source/CPack/cmCPackArchiveGenerator.cxx @@ -9,7 +9,6 @@ #include "cmSystemTools.h" #include "cmWorkingDirectory.h" -#include #include #include #include @@ -74,12 +73,10 @@ int cmCPackArchiveGenerator::addOneComponentToArchive( filePrefix += installPrefix + 1; filePrefix += "/"; } - std::vector::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); @@ -117,53 +114,47 @@ 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::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::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); } // Handle Orphan components (components not belonging to any groups) - std::map::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 + << 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); @@ -173,20 +164,18 @@ int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup) // CPACK_COMPONENTS_IGNORE_GROUPS is set // We build 1 package per component else { - std::map::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); @@ -217,11 +206,9 @@ int cmCPackArchiveGenerator::PackageComponentsAllInOne() DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0], archive); // The ALL COMPONENTS in ONE package case - std::map::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,16 +236,15 @@ int cmCPackArchiveGenerator::PackageFiles() // CASE 3 : NON COMPONENT package. DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0], archive); - std::vector::const_iterator fileIt; cmWorkingDirectory workdir(toplevel); - for (fileIt = files.begin(); fileIt != files.end(); ++fileIt) { + 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); + cmSystemTools::RelativePath(toplevel.c_str(), file.c_str()); + archive.Add(rp, 0, nullptr, false); if (!archive) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem while adding file< " - << *fileIt << "> to archive <" << packageFileNames[0] + << 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..f47ca7a74 100644 --- a/Source/CPack/cmCPackBundleGenerator.cxx +++ b/Source/CPack/cmCPackBundleGenerator.cxx @@ -19,7 +19,7 @@ cmCPackBundleGenerator::~cmCPackBundleGenerator() 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); @@ -213,8 +213,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::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 +222,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; 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 @@ -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 -#include unsigned long cmCPackComponent::GetInstalledSize( const std::string& installDir) const @@ -14,11 +13,10 @@ unsigned long cmCPackComponent::GetInstalledSize( return this->TotalSize; } - std::vector::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..f2907db20 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 #include @@ -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) { } 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.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..7fc3c26de 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -6,28 +6,17 @@ #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 -#include #include #include -#include #include #include -// 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& files); - cmCPackDebGenerator::cmCPackDebGenerator() { } @@ -115,37 +104,31 @@ 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::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::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 + << 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::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; @@ -346,10 +329,8 @@ int cmCPackDebGenerator::createDeb() { std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); dirName += '/'; - for (std::vector::const_iterator fileIt = - packageFiles.begin(); - fileIt != packageFiles.end(); ++fileIt) { - totalSize += cmSystemTools::FileLength(*fileIt); + for (std::string const& file : packageFiles) { + totalSize += cmSystemTools::FileLength(file); } } out << "Installed-Size: " << (totalSize + 1023) / 1024 << "\n"; @@ -410,7 +391,7 @@ int cmCPackDebGenerator::createDeb() compression_suffix = ".gz"; tar_compression_type = cmArchiveWrite::CompressGZip; } else if (!strcmp(debian_compression_type, "none")) { - compression_suffix = ""; + compression_suffix.clear(); tar_compression_type = cmArchiveWrite::CompressNone; } else { cmCPackLogger(cmCPackLog::LOG_ERROR, @@ -456,10 +437,7 @@ int cmCPackDebGenerator::createDeb() // we have to reconstruct the parent folders as well - for (std::vector::const_iterator fileIt = - packageFiles.begin(); - fileIt != packageFiles.end(); ++fileIt) { - std::string currentPath = *fileIt; + for (std::string currentPath : packageFiles) { 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 @@ -469,22 +447,40 @@ int cmCPackDebGenerator::createDeb() } } - for (std::set::const_iterator fileIt = orderedFiles.begin(); - fileIt != orderedFiles.end(); ++fileIt) { - cmCPackLogger(cmCPackLog::LOG_DEBUG, "FILEIT: \"" << *fileIt << "\"" + for (std::string const& file : orderedFiles) { + cmCPackLogger(cmCPackLog::LOG_DEBUG, "FILEIT: \"" << file << "\"" << std::endl); - std::string::size_type slashPos = fileIt->find('/', topLevelLength + 1); + std::string::size_type slashPos = file.find('/', topLevelLength + 1); std::string relativeDir = - fileIt->substr(topLevelLength, slashPos - topLevelLength); + 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(*fileIt, topLevelLength, ".", false)) { + if (!data_tar.Add(file, topLevelLength, ".", false)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem adding file to tar:" << std::endl << "#top level directory: " << strGenWDIR << std::endl - << "#file: " << *fileIt << std::endl + << "#file: " << file << std::endl << "#error:" << data_tar.GetError() << std::endl); return 0; } @@ -499,25 +495,21 @@ int cmCPackDebGenerator::createDeb() std::string topLevelWithTrailingSlash = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); topLevelWithTrailingSlash += '/'; - for (std::vector::const_iterator fileIt = - packageFiles.begin(); - fileIt != packageFiles.end(); ++fileIt) { + for (std::string const& file : packageFiles) { // hash only regular files - if (cmSystemTools::FileIsDirectory(*fileIt) || - cmSystemTools::FileIsSymlink(*fileIt)) { + if (cmSystemTools::FileIsDirectory(file) || + cmSystemTools::FileIsSymlink(file)) { continue; } - char md5sum[33]; - if (!cmSystemTools::ComputeFileMD5(*fileIt, md5sum)) { + std::string output = + cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5); + if (output.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem computing the md5 of " - << *fileIt << std::endl); + << file << std::endl); } - md5sum[32] = 0; - - std::string output(md5sum); - output += " " + *fileIt + "\n"; + output += " " + file + "\n"; // debian md5sums entries are like this: // 014f3604694729f3bf19263bac599765 usr/bin/ccmake // thus strip the full path (with the trailing slash) @@ -553,8 +545,8 @@ int cmCPackDebGenerator::createDeb() 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 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 @@ -634,9 +626,8 @@ int cmCPackDebGenerator::createDeb() std::vector controlExtraList; cmSystemTools::ExpandListArgument(controlExtra, controlExtraList); - for (std::vector::iterator i = controlExtraList.begin(); - i != controlExtraList.end(); ++i) { - std::string filenamename = cmsys::SystemTools::GetFilenameName(*i); + for (std::string const& i : controlExtraList) { + std::string filenamename = cmsys::SystemTools::GetFilenameName(i); std::string localcopy = strGenWDIR + "/" + filenamename; if (permissionStrictPolicy) { @@ -646,7 +637,7 @@ int cmCPackDebGenerator::createDeb() } // if we can copy the file, it means it does exist, let's add it: - if (cmsys::SystemTools::CopyFileIfDifferent(*i, localcopy)) { + if (cmsys::SystemTools::CopyFileIfDifferent(i, localcopy)) { control_tar.Add(localcopy, strGenWDIR.length(), "."); } } @@ -654,23 +645,25 @@ int cmCPackDebGenerator::createDeb() } // 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 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; + // 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 outputDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); + std::string const outputName = this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME"); + std::string const outputPath = outputDir + "/" + outputName; + std::string const tlDir = strGenWDIR + "/"; + cmGeneratedFileStream debStream; + debStream.Open(outputPath.c_str(), false, true); + cmArchiveWrite deb(debStream, cmArchiveWrite::CompressNone, "arbsd"); + if (!deb.Add(tlDir + "debian-binary", tlDir.length()) || + !deb.Add(tlDir + "control.tar.gz", tlDir.length()) || + !deb.Add(tlDir + "data.tar" + compression_suffix, tlDir.length())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error creating debian package:" + << std::endl + << "#top level directory: " << outputDir << std::endl + << "#file: " << outputName << std::endl + << "#error:" << deb.GetError() << std::endl); return 0; } return 1; @@ -695,252 +688,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 "!\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(sizeof(buf)) - ? static_cast(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& 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::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..b4f0c7972 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,11 +57,11 @@ 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(); diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index d26d5bc1a..1e1543f9d 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -136,17 +136,17 @@ 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); + << 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); + << language << ".menu.txt" << std::endl); return 0; } } @@ -185,19 +185,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; @@ -226,14 +226,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,9 +242,9 @@ 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().c_str(), output, + output, &exit_code, nullptr, + this->GeneratorVerbose, 0); if (!result || exit_code) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Error executing: " << command.str() @@ -417,6 +417,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, 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 << "\""; @@ -448,6 +449,8 @@ 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; @@ -481,7 +484,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, @@ -551,16 +554,17 @@ 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); } - 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 +577,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); @@ -767,7 +769,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 +796,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 +866,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 #include @@ -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& lines, std::string* error); void EscapeQuotesAndBackslashes(std::string& line); diff --git a/Source/CPack/cmCPackFreeBSDGenerator.cxx b/Source/CPack/cmCPackFreeBSDGenerator.cxx new file mode 100644 index 000000000..91ae1a23f --- /dev/null +++ b/Source/CPack/cmCPackFreeBSDGenerator.cxx @@ -0,0 +1,359 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackFreeBSDGenerator.h" + +#include "cmArchiveWrite.h" +#include "cmCPackArchiveGenerator.h" +#include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" + +// Needed for ::open() and ::stat() +#include +#include +#include +#include + +#include + +#include + +cmCPackFreeBSDGenerator::cmCPackFreeBSDGenerator() + : cmCPackArchiveGenerator(cmArchiveWrite::CompressXZ, "paxr") +{ +} + +int cmCPackFreeBSDGenerator::InitializeInternal() +{ + this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr/local"); + this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0"); + return this->Superclass::InitializeInternal(); +} + +cmCPackFreeBSDGenerator::~cmCPackFreeBSDGenerator() +{ +} + +// This is a wrapper, for use only in stream-based output, +// that will output a string in UCL escaped fashion (in particular, +// quotes and backslashes are escaped). The list of characters +// to escape is taken from https://github.com/vstakhov/libucl +// (which is the reference implementation pkg(8) refers to). +class EscapeQuotes +{ +public: + const std::string& value; + + EscapeQuotes(const std::string& s) + : value(s) + { + } +}; + +// Output a string as "string" with escaping applied. +cmGeneratedFileStream& operator<<(cmGeneratedFileStream& s, + const EscapeQuotes& v) +{ + s << '"'; + for (std::string::size_type i = 0; i < v.value.length(); ++i) { + char c = v.value[i]; + switch (c) { + case '\n': + s << "\\n"; + break; + case '\r': + s << "\\r"; + break; + case '\b': + s << "\\b"; + break; + case '\t': + s << "\\t"; + break; + case '\f': + s << "\\f"; + break; + case '\\': + s << "\\\\"; + break; + case '"': + s << "\\\""; + break; + default: + s << c; + break; + } + } + s << '"'; + return s; +} + +// The following classes are all helpers for writing out the UCL +// manifest file (it also looks like JSON). ManifestKey just has +// a (string-valued) key; subclasses add a specific kind of +// value-type to the key, and implement write_value() to output +// the corresponding UCL. +class ManifestKey +{ +public: + std::string key; + + ManifestKey(const std::string& k) + : key(k) + { + } + + virtual ~ManifestKey() {} + + // Output the value associated with this key to the stream @p s. + // Format is to be decided by subclasses. + virtual void write_value(cmGeneratedFileStream& s) const = 0; +}; + +// Basic string-value (e.g. "name": "cmake") +class ManifestKeyValue : public ManifestKey +{ +public: + std::string value; + + ManifestKeyValue(const std::string& k, const std::string& v) + : ManifestKey(k) + , value(v) + { + } + + void write_value(cmGeneratedFileStream& s) const override + { + s << EscapeQuotes(value); + } +}; + +// List-of-strings values (e.g. "licenses": ["GPLv2", "LGPLv2"]) +class ManifestKeyListValue : public ManifestKey +{ +public: + typedef std::vector VList; + VList value; + + ManifestKeyListValue(const std::string& k) + : ManifestKey(k) + { + } + + ManifestKeyListValue& operator<<(const std::string& v) + { + value.push_back(v); + return *this; + } + + ManifestKeyListValue& operator<<(const std::vector& v) + { + for (VList::const_iterator it = v.begin(); it != v.end(); ++it) { + (*this) << (*it); + } + return *this; + } + + void write_value(cmGeneratedFileStream& s) const override + { + bool with_comma = false; + + s << '['; + for (VList::const_iterator it = value.begin(); it != value.end(); ++it) { + s << (with_comma ? ',' : ' '); + s << EscapeQuotes(*it); + with_comma = true; + } + s << " ]"; + } +}; + +// Deps: actually a dictionary, but we'll treat it as a +// list so we only name the deps, and produce dictionary- +// like output via write_value() +class ManifestKeyDepsValue : public ManifestKeyListValue +{ +public: + ManifestKeyDepsValue(const std::string& k) + : ManifestKeyListValue(k) + { + } + + void write_value(cmGeneratedFileStream& s) const override + { + s << "{\n"; + for (VList::const_iterator it = value.begin(); it != value.end(); ++it) { + s << " \"" << *it << "\": {\"origin\": \"" << *it << "\"},\n"; + } + s << '}'; + } +}; + +// Write one of the key-value classes (above) to the stream @p s +cmGeneratedFileStream& operator<<(cmGeneratedFileStream& s, + const ManifestKey& v) +{ + s << '"' << v.key << "\": "; + v.write_value(s); + s << ",\n"; + return s; +} + +// Look up variable; if no value is set, returns an empty string; +// basically a wrapper that handles the NULL-ptr return from GetOption(). +std::string cmCPackFreeBSDGenerator::var_lookup(const char* var_name) +{ + const char* pv = this->GetOption(var_name); + if (!pv) { + return std::string(); + } else { + return pv; + } +} + +// Produce UCL in the given @p manifest file for the common +// manifest fields (common to the compact and regular formats), +// by reading the CPACK_FREEBSD_* variables. +void cmCPackFreeBSDGenerator::write_manifest_fields( + cmGeneratedFileStream& manifest) +{ + manifest << ManifestKeyValue("name", + var_lookup("CPACK_FREEBSD_PACKAGE_NAME")); + manifest << ManifestKeyValue("origin", + var_lookup("CPACK_FREEBSD_PACKAGE_ORIGIN")); + manifest << ManifestKeyValue("version", + var_lookup("CPACK_FREEBSD_PACKAGE_VERSION")); + manifest << ManifestKeyValue("maintainer", + var_lookup("CPACK_FREEBSD_PACKAGE_MAINTAINER")); + manifest << ManifestKeyValue("comment", + var_lookup("CPACK_FREEBSD_PACKAGE_COMMENT")); + manifest << ManifestKeyValue( + "desc", var_lookup("CPACK_FREEBSD_PACKAGE_DESCRIPTION")); + manifest << ManifestKeyValue("www", var_lookup("CPACK_FREEBSD_PACKAGE_WWW")); + std::vector licenses; + cmSystemTools::ExpandListArgument( + var_lookup("CPACK_FREEBSD_PACKAGE_LICENSE"), licenses); + std::string licenselogic("single"); + if (licenses.size() < 1) { + cmSystemTools::SetFatalErrorOccured(); + } else if (licenses.size() > 1) { + licenselogic = var_lookup("CPACK_FREEBSD_PACKAGE_LICENSE_LOGIC"); + } + manifest << ManifestKeyValue("licenselogic", licenselogic); + manifest << (ManifestKeyListValue("licenses") << licenses); + std::vector categories; + cmSystemTools::ExpandListArgument( + var_lookup("CPACK_FREEBSD_PACKAGE_CATEGORIES"), categories); + manifest << (ManifestKeyListValue("categories") << categories); + manifest << ManifestKeyValue("prefix", var_lookup("CMAKE_INSTALL_PREFIX")); + std::vector deps; + cmSystemTools::ExpandListArgument(var_lookup("CPACK_FREEBSD_PACKAGE_DEPS"), + deps); + if (deps.size() > 0) { + manifest << (ManifestKeyDepsValue("deps") << deps); + } +} + +// Package only actual files; others are ignored (in particular, +// intermediate subdirectories are ignored). +static bool ignore_file(const std::string& filename) +{ + struct stat statbuf; + + if (!((stat(filename.c_str(), &statbuf) >= 0) && + ((statbuf.st_mode & S_IFMT) == S_IFREG))) { + return true; + } + // May be other reasons to return false + return false; +} + +// Write the given list of @p files to the manifest stream @p s, +// as the UCL field "files" (which is dictionary-valued, to +// associate filenames with hashes). All the files are transformed +// to paths relative to @p toplevel, with a leading / (since the paths +// in FreeBSD package files are supposed to be absolute). +void write_manifest_files(cmGeneratedFileStream& s, + const std::string& toplevel, + const std::vector& files) +{ + const char* c_toplevel = toplevel.c_str(); + std::vector::const_iterator it; + + s << "\"files\": {\n"; + for (it = files.begin(); it != files.end(); ++it) { + s << " \"/" << cmSystemTools::RelativePath(c_toplevel, it->c_str()) + << "\": \"" + << "" + << "\",\n"; + } + s << " },\n"; +} + +static bool has_suffix(const std::string& str, const std::string& suffix) +{ + return str.size() >= suffix.size() && + str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; +} + +int cmCPackFreeBSDGenerator::PackageFiles() +{ + if (!this->ReadListFile("CPackFreeBSD.cmake")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error while execution CPackFreeBSD.cmake" << std::endl); + return 0; + } + + std::vector::const_iterator fileIt; + std::string dir = cmSystemTools::GetCurrentWorkingDirectory(); + cmSystemTools::ChangeDirectory(toplevel); + + files.erase(std::remove_if(files.begin(), files.end(), ignore_file), + files.end()); + + std::string manifestname = toplevel + "/+MANIFEST"; + { + cmGeneratedFileStream manifest(manifestname.c_str()); + manifest << "{\n"; + write_manifest_fields(manifest); + write_manifest_files(manifest, toplevel, files); + manifest << "}\n"; + } + + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl); + + if (WantsComponentInstallation()) { + // CASE 1 : COMPONENT ALL-IN-ONE package + // If ALL COMPONENTS in ONE package has been requested + // then the package file is unique and should be open here. + if (componentPackageMethod == ONE_PACKAGE) { + return PackageComponentsAllInOne(); + } + // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one) + // There will be 1 package for each component group + // however one may require to ignore component group and + // in this case you'll get 1 package for each component. + return PackageComponents(componentPackageMethod == + ONE_PACKAGE_PER_COMPONENT); + } + + std::string output_dir = + cmSystemTools::CollapseCombinedPath(toplevel, "../"); + pkg_create_from_manifest(output_dir.c_str(), ::TXZ, toplevel.c_str(), + manifestname.c_str(), NULL); + + std::string broken_suffix = std::string("-") + + var_lookup("CPACK_TOPLEVEL_TAG") + std::string(GetOutputExtension()); + for (std::vector::iterator it = packageFileNames.begin(); + it != packageFileNames.end(); ++it) { + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Packagefile " << *it << std::endl); + if (has_suffix(*it, broken_suffix)) { + it->replace(it->size() - broken_suffix.size(), std::string::npos, + GetOutputExtension()); + break; + } + } + + cmSystemTools::ChangeDirectory(dir); + return 1; +} diff --git a/Source/CPack/cmCPackFreeBSDGenerator.h b/Source/CPack/cmCPackFreeBSDGenerator.h new file mode 100644 index 000000000..99d2e2421 --- /dev/null +++ b/Source/CPack/cmCPackFreeBSDGenerator.h @@ -0,0 +1,37 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackFreeBSDGenerator_h +#define cmCPackFreeBSDGenerator_h + +#include + +#include "cmCPackArchiveGenerator.h" +#include "cmCPackGenerator.h" + +class cmGeneratedFileStream; + +/** \class cmCPackFreeBSDGenerator + * \brief A generator for FreeBSD package files (TXZ with a manifest) + * + */ +class cmCPackFreeBSDGenerator : public cmCPackArchiveGenerator +{ +public: + cmCPackTypeMacro(cmCPackFreeBSDGenerator, cmCPackArchiveGenerator); + /** + * Construct generator + */ + cmCPackFreeBSDGenerator(); + ~cmCPackFreeBSDGenerator() override; + + int InitializeInternal() override; + int PackageFiles() override; + +protected: + const char* GetOutputExtension() override { return ".txz"; } + + std::string var_lookup(const char* var_name); + void write_manifest_fields(cmGeneratedFileStream&); +}; + +#endif diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index d8e2753cf..ecb5adb47 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -6,6 +6,7 @@ #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" #include +#include // IWYU pragma: keep #include #include "cmCPackComponentGroup.h" @@ -17,7 +18,6 @@ #include "cmStateSnapshot.h" #include "cmWorkingDirectory.h" #include "cmXMLSafe.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(__HAIKU__) @@ -28,14 +28,14 @@ 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) @@ -156,7 +156,7 @@ int cmCPackGenerator::PrepareNames() } const char* algoSignature = this->GetOption("CPACK_PACKAGE_CHECKSUM"); if (algoSignature) { - if (cmCryptoHash::New(algoSignature).get() == CM_NULLPTR) { + if (!cmCryptoHash::New(algoSignature)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot recognize algorithm: " << algoSignature << std::endl); return 0; @@ -248,25 +248,23 @@ int cmCPackGenerator::InstallProjectViaInstallCommands( cmSystemTools::PutEnv(tempInstallDirectoryEnv); std::vector installCommandsVector; cmSystemTools::ExpandListArgument(installCommands, installCommandsVector); - std::vector::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); + cmSystemTools::RunSingleCommand(ic.c_str(), &output, &output, &retVal, + nullptr, this->GeneratorVerbose, 0); if (!resB || retVal) { std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); tmpFile += "/InstallOutput.log"; cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << *it << std::endl + ofs << "# Run command: " << ic << std::endl << "# Output:" << std::endl << output << std::endl; cmCPackLogger( cmCPackLog::LOG_ERROR, "Problem running install command: " - << *it << std::endl + << ic << std::endl << "Please check " << tmpFile << " for errors" << std::endl); return 0; } @@ -286,12 +284,10 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( std::vector ignoreFilesRegexString; cmSystemTools::ExpandListArgument(cpackIgnoreFiles, ignoreFilesRegexString); - std::vector::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.push_back(ifr.c_str()); } } const char* installDirectories = @@ -313,7 +309,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( const std::string& tempDir = tempInstallDirectory; for (it = installDirectoriesVector.begin(); it != installDirectoriesVector.end(); ++it) { - std::vector > symlinkedFiles; + std::vector> symlinkedFiles; cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl); cmsys::Glob gl; std::string top = *it; @@ -334,15 +330,14 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( files = gl.GetFiles(); std::vector::iterator gfit; std::vector::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.c_str())) { cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Ignore file: " << inFile << std::endl); skip = true; @@ -353,7 +348,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( } std::string filePath = tempDir; filePath += "/" + subdir + "/" + - cmSystemTools::RelativePath(top.c_str(), gfit->c_str()); + cmSystemTools::RelativePath(top.c_str(), gf.c_str()); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: " << inFile << " -> " << filePath << std::endl); /* If the file is a symlink we will have to re-create it */ @@ -377,33 +372,30 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( } /* rebuild symlinks in the installed tree */ if (!symlinkedFiles.empty()) { - std::vector >::iterator - symlinkedIt; std::string curDir = cmSystemTools::GetCurrentWorkingDirectory(); std::string goToDir = tempDir; goToDir += "/" + subdir; cmCPackLogger(cmCPackLog::LOG_DEBUG, "Change dir to: " << goToDir << std::endl); cmWorkingDirectory workdir(goToDir); - for (symlinkedIt = symlinkedFiles.begin(); - symlinkedIt != symlinkedFiles.end(); ++symlinkedIt) { + for (auto const& symlinked : symlinkedFiles) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "Will create a symlink: " - << symlinkedIt->second << "--> " - << symlinkedIt->first << std::endl); + << symlinked.second << "--> " << symlinked.first + << std::endl); // make sure directory exists for symlink std::string destDir = - cmSystemTools::GetFilenamePath(symlinkedIt->second); + cmSystemTools::GetFilenamePath(symlinked.second); if (!destDir.empty() && !cmSystemTools::MakeDirectory(destDir)) { 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)) { + if (!cmSystemTools::CreateSymlink(symlinked.first, + symlinked.second)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create symlink: " - << symlinkedIt->second << "--> " - << symlinkedIt->first << std::endl); + << symlinked.second << "--> " << symlinked.first + << std::endl); return 0; } } @@ -424,10 +416,7 @@ int cmCPackGenerator::InstallProjectViaInstallScript( << std::endl); std::vector cmakeScriptsVector; cmSystemTools::ExpandListArgument(cmakeScripts, cmakeScriptsVector); - std::vector::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); @@ -533,10 +522,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( if (installTypes && *installTypes) { std::vector installTypesVector; cmSystemTools::ExpandListArgument(installTypes, installTypesVector); - std::vector::iterator installTypeIt; - for (installTypeIt = installTypesVector.begin(); - installTypeIt != installTypesVector.end(); ++installTypeIt) { - this->GetInstallationType(installProjectName, *installTypeIt); + for (std::string const& installType : installTypesVector) { + this->GetInstallationType(installProjectName, installType); } } @@ -546,10 +533,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( const char* components = this->GetOption(componentsVar); if (components && *components) { cmSystemTools::ExpandListArgument(components, componentsVector); - std::vector::iterator compIt; - for (compIt = componentsVector.begin(); - compIt != componentsVector.end(); ++compIt) { - GetComponent(installProjectName, *compIt); + for (std::string const& comp : componentsVector) { + GetComponent(installProjectName, comp); } componentInstall = true; } @@ -610,11 +595,9 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( "- Install project: " << installProjectName << std::endl); // Run the installation for each component - std::vector::iterator componentIt; - for (componentIt = componentsVector.begin(); - componentIt != componentsVector.end(); ++componentIt) { + for (std::string const& component : componentsVector) { std::string tempInstallDirectory = baseTempInstallDirectory; - installComponent = *componentIt; + installComponent = component; if (componentInstall) { cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Install component: " << installComponent << std::endl); @@ -627,8 +610,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( cm.AddCMakePaths(); cm.SetProgressCallback(cmCPackGeneratorProgress, this); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR mf( - new cmMakefile(&gg, cm.GetCurrentSnapshot())); + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); if (!installSubDirectory.empty() && installSubDirectory != "/" && installSubDirectory != ".") { tempInstallDirectory += installSubDirectory; @@ -674,11 +656,11 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( if (this->GetOption("CPACK_INSTALL_PREFIX")) { dir += this->GetOption("CPACK_INSTALL_PREFIX"); } - mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str()); + mf.AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str()); cmCPackLogger( cmCPackLog::LOG_DEBUG, - "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)" + "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf.AddDefinition)" << std::endl); cmCPackLogger(cmCPackLog::LOG_DEBUG, "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" @@ -715,8 +697,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( return 0; } } else { - mf->AddDefinition("CMAKE_INSTALL_PREFIX", - tempInstallDirectory.c_str()); + mf.AddDefinition("CMAKE_INSTALL_PREFIX", + tempInstallDirectory.c_str()); if (!cmsys::SystemTools::MakeDirectory( tempInstallDirectory.c_str())) { @@ -727,7 +709,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( } cmCPackLogger(cmCPackLog::LOG_DEBUG, - "- Using non-DESTDIR install... (mf->AddDefinition)" + "- Using non-DESTDIR install... (mf.AddDefinition)" << std::endl); cmCPackLogger(cmCPackLog::LOG_DEBUG, "- Setting CMAKE_INSTALL_PREFIX to '" @@ -735,19 +717,19 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( } if (!buildConfig.empty()) { - mf->AddDefinition("BUILD_TYPE", buildConfig.c_str()); + mf.AddDefinition("BUILD_TYPE", buildConfig.c_str()); } std::string installComponentLowerCase = cmSystemTools::LowerCase(installComponent); if (installComponentLowerCase != "all") { - mf->AddDefinition("CMAKE_INSTALL_COMPONENT", - installComponent.c_str()); + mf.AddDefinition("CMAKE_INSTALL_COMPONENT", + installComponent.c_str()); } // strip on TRUE, ON, 1, one or several file names, but not on // FALSE, OFF, 0 and an empty string if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES"))) { - mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1"); + mf.AddDefinition("CMAKE_INSTALL_DO_STRIP", "1"); } // Remember the list of files before installation // of the current component (if we are in component install) @@ -767,7 +749,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( // 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"); + mf.AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", "1"); } // If current CPack generator does support // ABSOLUTE INSTALL DESTINATION or CPack has been asked for @@ -775,18 +757,17 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( // 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"); + mf.AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", "1"); } // do installation - int res = mf->ReadListFile(installFile.c_str()); + 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( + if (mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) { + mf.AddDefinition( "CPACK_ABSOLUTE_DESTINATION_FILES", - mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")); + mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")); } // Now rebuild the list of files after installation @@ -820,13 +801,12 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( } } - if (CM_NULLPTR != - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) { + if (nullptr != mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) { if (!absoluteDestFiles.empty()) { absoluteDestFiles += ";"; } absoluteDestFiles += - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); + mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Got some ABSOLUTE DESTINATION FILES: " << absoluteDestFiles << std::endl); @@ -835,18 +815,18 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( std::string absoluteDestFileComponent = std::string("CPACK_ABSOLUTE_DESTINATION_FILES") + "_" + GetComponentInstallDirNameSuffix(installComponent); - if (CM_NULLPTR != this->GetOption(absoluteDestFileComponent)) { + if (nullptr != this->GetOption(absoluteDestFileComponent)) { std::string absoluteDestFilesListComponent = this->GetOption(absoluteDestFileComponent); absoluteDestFilesListComponent += ";"; absoluteDestFilesListComponent += - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); + mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); this->SetOption(absoluteDestFileComponent, absoluteDestFilesListComponent.c_str()); } else { this->SetOption( absoluteDestFileComponent, - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")); + mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")); } } } @@ -982,7 +962,7 @@ int cmCPackGenerator::DoPackage() /* Prepare checksum algorithm*/ const char* algo = this->GetOption("CPACK_PACKAGE_CHECKSUM"); - CM_AUTO_PTR crypto = cmCryptoHash::New(algo ? algo : ""); + std::unique_ptr crypto = cmCryptoHash::New(algo ? algo : ""); /* * Copy the generated packages to final destination @@ -992,12 +972,11 @@ int cmCPackGenerator::DoPackage() */ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copying final package(s) [" << packageFileNames.size() << "]:" << std::endl); - std::vector::iterator it; /* 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): " @@ -1016,10 +995,9 @@ int cmCPackGenerator::DoPackage() << 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) { @@ -1225,7 +1203,7 @@ 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"); } @@ -1407,7 +1385,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"); @@ -1421,10 +1399,9 @@ cmCPackComponent* cmCPackGenerator::GetComponent( std::vector installTypesVector; cmSystemTools::ExpandListArgument(installTypes, installTypesVector); std::vector::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)); } } @@ -1434,9 +1411,8 @@ cmCPackComponent* cmCPackGenerator::GetComponent( std::vector dependsVector; cmSystemTools::ExpandListArgument(depends, dependsVector); std::vector::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 +1451,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..4e3a6e038 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 #include @@ -105,7 +105,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 @@ -299,7 +299,7 @@ private: #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..4b81bbc5f 100644 --- a/Source/CPack/cmCPackGeneratorFactory.cxx +++ b/Source/CPack/cmCPackGeneratorFactory.cxx @@ -2,13 +2,16 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackGeneratorFactory.h" -#include "cmConfigure.h" #include #include #include "IFW/cmCPackIFWGenerator.h" #include "cmAlgorithms.h" #include "cmCPack7zGenerator.h" +#ifdef HAVE_FREEBSD_PKG +#include "cmCPackFreeBSDGenerator.h" +#endif +#include "cmCPackDebGenerator.h" #include "cmCPackGenerator.h" #include "cmCPackLog.h" #include "cmCPackNSISGenerator.h" @@ -34,7 +37,6 @@ #if !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__BEOS__) && \ !defined(__HAIKU__) -#include "cmCPackDebGenerator.h" #include "cmCPackRPMGenerator.h" #endif @@ -99,6 +101,10 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory() this->RegisterGenerator("TZ", "Tar Compress compression", cmCPackTarCompressGenerator::CreateGenerator); } + if (cmCPackDebGenerator::CanGenerate()) { + this->RegisterGenerator("DEB", "Debian packages", + cmCPackDebGenerator::CreateGenerator); + } #ifdef __APPLE__ if (cmCPackDragNDropGenerator::CanGenerate()) { this->RegisterGenerator("DragNDrop", "Mac OSX Drag And Drop", @@ -123,15 +129,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 +152,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 +165,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/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 #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/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 9697a3832..ddf104c93 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -59,11 +59,10 @@ int cmCPackNSISGenerator::PackageFiles() std::string nsisInstallOptions = nsisFileName + "/NSIS.InstallOptions.ini"; nsisFileName += "/project.nsi"; std::ostringstream str; - std::vector::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()); + cmSystemTools::RelativePath(toplevel.c_str(), file.c_str()); if (!this->Components.empty()) { const std::string::size_type pos = fileN.find('/'); @@ -87,12 +86,11 @@ int cmCPackNSISGenerator::PackageFiles() this->SetOptionIfNotSet("CPACK_NSIS_DELETE_FILES", str.str().c_str()); std::vector dirs; this->GetListOfSubdirectories(toplevel.c_str(), dirs); - std::vector::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()); + cmSystemTools::RelativePath(toplevel.c_str(), dir.c_str()); if (fileN.empty()) { continue; } @@ -205,65 +203,57 @@ int cmCPackNSISGenerator::PackageFiles() // in a vector based on the indices, and print them in that order. std::vector installTypes( this->InstallationTypes.size()); - std::map::iterator installTypeIt; - for (installTypeIt = this->InstallationTypes.begin(); - installTypeIt != this->InstallationTypes.end(); ++installTypeIt) { - installTypes[installTypeIt->second.Index - 1] = &installTypeIt->second; - } - std::vector::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::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 + "} \"" + + this->TranslateNewlines(group.second.Description) + "\"\n"; } } // Create the remaining components, which aren't associated with groups. - std::map::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 += 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 + "} \"" + + this->TranslateNewlines(comp.second.Description) + "\"\n"; } } @@ -313,7 +303,7 @@ int cmCPackNSISGenerator::PackageFiles() int retVal = 1; bool res = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &output, &retVal, - CM_NULLPTR, this->GeneratorVerbose, 0); + nullptr, this->GeneratorVerbose, 0); if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); ofs << "# Run command: " << nsisCmd << std::endl @@ -337,7 +327,7 @@ 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()" @@ -412,7 +402,7 @@ int cmCPackNSISGenerator::InitializeInternal() int retVal = 1; bool resS = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &output, &retVal, - CM_NULLPTR, this->GeneratorVerbose, 0); + nullptr, this->GeneratorVerbose, 0); cmsys::RegularExpression versionRex("v([0-9]+.[0-9]+)"); cmsys::RegularExpression versionRexCVS("v(.*)\\.cvs"); if (!resS || retVal || @@ -463,11 +453,9 @@ int cmCPackNSISGenerator::InitializeInternal() cmSystemTools::ExpandListArgument(cpackPackageDeskTopLinks, cpackPackageDesktopLinksVector); - for (std::vector::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: " @@ -647,11 +635,9 @@ std::string cmCPackNSISGenerator::CreateComponentDescription( componentCode += " SectionIn RO\n"; } else if (!component->InstallationTypes.empty()) { std::ostringstream out; - std::vector::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"; } @@ -730,19 +716,17 @@ std::string cmCPackNSISGenerator::CreateComponentDescription( unsigned long totalSize = 0; { // the scope is needed for cmGeneratedFileStream cmGeneratedFileStream out(zipListFileName.c_str()); - std::vector::iterator fileIt; - for (fileIt = component->Files.begin(); fileIt != component->Files.end(); - ++fileIt) { + 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); } } @@ -798,17 +782,14 @@ std::string cmCPackNSISGenerator::CreateComponentDescription( macrosOut << "!macro Remove_${" << component->Name << "}\n"; macrosOut << " IntCmp $" << component->Name << "_was_installed 0 noremove_" << component->Name << "\n"; - std::vector::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 +822,14 @@ std::string cmCPackNSISGenerator::CreateSelectionDependenciesDescription( visited.insert(component); std::ostringstream out; - std::vector::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 +845,16 @@ std::string cmCPackNSISGenerator::CreateDeselectionDependenciesDescription( visited.insert(component); std::ostringstream out; - std::vector::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 +878,16 @@ std::string cmCPackNSISGenerator::CreateComponentGroupDescription( code += "\"" + group->DisplayName + "\" " + group->Name + "\n"; } - std::vector::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::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& 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..8d3c40c5c 100644 --- a/Source/CPack/cmCPackOSXX11Generator.cxx +++ b/Source/CPack/cmCPackOSXX11Generator.cxx @@ -144,8 +144,8 @@ 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] << "\""; + << "\" 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 @@ -154,9 +154,9 @@ int cmCPackOSXX11Generator::PackageFiles() 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().c_str(), &output, + &output, &retVal, nullptr, + this->GeneratorVerbose, 0); if (res && !retVal) { numTries = -1; break; 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 @@ -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..4f5b2a05a 100644 --- a/Source/CPack/cmCPackPKGGenerator.cxx +++ b/Source/CPack/cmCPackPKGGenerator.cxx @@ -42,9 +42,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) @@ -70,7 +70,7 @@ void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile) std::map::iterator groupIt; for (groupIt = this->ComponentGroups.begin(); groupIt != this->ComponentGroups.end(); ++groupIt) { - if (groupIt->second.ParentGroup == 0) { + if (groupIt->second.ParentGroup == nullptr) { CreateChoiceOutline(groupIt->second, xout); } } 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 #include @@ -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..dbcb02231 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.cxx +++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx @@ -275,8 +275,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 +288,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().c_str(), &output, + &output, &retVal, nullptr, + this->GeneratorVerbose, 0); if (res && !retVal) { numTries = -1; break; @@ -466,7 +467,7 @@ bool cmCPackPackageMakerGenerator::RunPackageMaker(const char* command, std::string output; int retVal = 1; bool res = cmSystemTools::RunSingleCommand( - command, &output, &output, &retVal, 0, this->GeneratorVerbose, 0); + command, &output, &output, &retVal, nullptr, this->GeneratorVerbose, 0); cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker" << std::endl); if (!res || retVal) { 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..6a6dc828f 100644 --- a/Source/CPack/cmCPackProductBuildGenerator.cxx +++ b/Source/CPack/cmCPackProductBuildGenerator.cxx @@ -54,7 +54,7 @@ int cmCPackProductBuildGenerator::PackageFiles() } else { if (!this->GenerateComponentPackage(basePackageDir, this->GetOption("CPACK_PACKAGE_NAME"), - toplevel, NULL)) { + toplevel, nullptr)) { return 0; } } @@ -145,9 +145,9 @@ bool cmCPackProductBuildGenerator::RunProductBuild(const std::string& command) cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl); std::string output, error_output; int retVal = 1; - bool res = - cmSystemTools::RunSingleCommand(command.c_str(), &output, &error_output, - &retVal, 0, this->GeneratorVerbose, 0); + bool res = cmSystemTools::RunSingleCommand(command.c_str(), &output, + &error_output, &retVal, nullptr, + this->GeneratorVerbose, 0); cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running command" << std::endl); if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); @@ -174,7 +174,7 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage( 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 @@ -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..e40b74d7e 100644 --- a/Source/CPack/cmCPackRPMGenerator.cxx +++ b/Source/CPack/cmCPackRPMGenerator.cxx @@ -148,7 +148,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); @@ -214,7 +214,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); @@ -299,7 +299,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) { cmCPackLogger( cmCPackLog::LOG_VERBOSE, "Component <" << compIt->second.Name @@ -430,7 +430,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..3d7fd3c14 100644 --- a/Source/CPack/cmCPackSTGZGenerator.cxx +++ b/Source/CPack/cmCPackSTGZGenerator.cxx @@ -6,7 +6,6 @@ #include #include #include -#include #include "cmCPackGenerator.h" #include "cmCPackLog.h" @@ -48,9 +47,8 @@ int cmCPackSTGZGenerator::PackageFiles() * have generated several packages (component packaging) * so we must iterate over generated packages. */ - for (std::vector::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 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.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.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.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.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.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..addb54ea0 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 #include +#include // IWYU pragma: keep #include #include #include @@ -25,17 +25,16 @@ #include "cmMakefile.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 [options]" }, - { CM_NULLPTR, CM_NULLPTR } + { nullptr, " cpack -G [options]" }, + { nullptr, nullptr } }; static const char* cmDocumentationOptions[][2] = { @@ -49,7 +48,7 @@ static const char* cmDocumentationOptions[][2] = { { "-R ", "override/define CPACK_PACKAGE_VERSION" }, { "-B ", "override/define CPACK_PACKAGE_DIRECTORY" }, { "--vendor ", "override/define CPACK_PACKAGE_VENDOR" }, - { CM_NULLPTR, CM_NULLPTR } + { nullptr, nullptr } }; int cpackUnknownArgument(const char* /*unused*/, void* /*unused*/) @@ -136,7 +135,7 @@ int main(int argc, char const* const* argv) cpackDefinitions definitions; definitions.Log = &log; - cpackConfigFile = ""; + cpackConfigFile.clear(); cmsys::CommandLineArguments arg; arg.Initialize(argc, argv); @@ -193,10 +192,9 @@ int main(int argc, char const* const* argv) cminst.SetHomeOutputDirectory(""); cminst.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator cmgg(&cminst); - CM_AUTO_PTR 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 bool cpackConfigFileSpecified = true; @@ -208,7 +206,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 +224,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.c_str())) { 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.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Error reading CMakeSystemSpecificInformation.cmake" << std::endl); @@ -243,7 +241,7 @@ 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())) { @@ -251,7 +249,7 @@ int main(int argc, char const* const* argv) cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Read CPack configuration file: " << cpackConfigFile << std::endl); - if (!globalMF->ReadListFile(cpackConfigFile.c_str())) { + if (!globalMF.ReadListFile(cpackConfigFile.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Problem reading CPack config file: \"" << cpackConfigFile << "\"" << std::endl); @@ -265,58 +263,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); } else { std::vector generatorsVector; cmSystemTools::ExpandListArgument(genList, generatorsVector); - std::vector::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")) { @@ -355,13 +348,14 @@ 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; @@ -414,12 +408,10 @@ int main(int argc, char const* const* argv) doc.PrependSection("Options", cmDocumentationOptions); std::vector 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; + e.Name = g.first; + e.Brief = g.second; v.push_back(e); } doc.SetSection("Generators", v); diff --git a/Source/CTest/cmCTestBZR.cxx b/Source/CTest/cmCTestBZR.cxx index 94f39c265..015220091 100644 --- a/Source/CTest/cmCTestBZR.cxx +++ b/Source/CTest/cmCTestBZR.cxx @@ -98,7 +98,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 +123,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 +136,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> "); @@ -182,15 +182,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(this->Parser), cmBZRXMLParserUnknownEncodingHandler, - CM_NULLPTR); + nullptr); } return res; } @@ -207,14 +207,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 +239,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); } - 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 +274,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 +294,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 +309,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 +325,7 @@ private: return true; } - bool ProcessLine() CM_OVERRIDE + bool ProcessLine() override { if (this->RegexUpdate.find(this->Line)) { this->DoPath(this->RegexUpdate.match(1)[0], @@ -373,14 +373,13 @@ bool cmCTestBZR::UpdateImpl() bzr_update.push_back(this->CommandLineTool.c_str()); bzr_update.push_back("pull"); - for (std::vector::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 +407,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 +431,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 +465,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/cmCTestBatchTestHandler.cxx b/Source/CTest/cmCTestBatchTestHandler.cxx index beee53a13..2eed8bed9 100644 --- a/Source/CTest/cmCTestBatchTestHandler.cxx +++ b/Source/CTest/cmCTestBatchTestHandler.cxx @@ -29,10 +29,9 @@ void cmCTestBatchTestHandler::WriteBatchScript() fout.open(this->Script.c_str()); fout << "#!/bin/sh\n"; - for (TestMap::iterator i = this->Tests.begin(); i != this->Tests.end(); - ++i) { - this->WriteSrunArgs(i->first, fout); - this->WriteTestCommand(i->first, fout); + for (auto const& t : this->Tests) { + this->WriteSrunArgs(t.first, fout); + this->WriteTestCommand(t.first, fout); fout << "\n"; } fout.flush(); @@ -80,9 +79,8 @@ void cmCTestBatchTestHandler::WriteTestCommand(int test, std::ostream& fout) this->TestHandler->GenerateTestCommand(processArgs, test); processArgs.push_back(command); - for (std::vector::iterator arg = processArgs.begin(); - arg != processArgs.end(); ++arg) { - fout << *arg << " "; + for (std::string const& arg : processArgs) { + fout << arg << " "; } std::vector::iterator i = args.begin(); diff --git a/Source/CTest/cmCTestBatchTestHandler.h b/Source/CTest/cmCTestBatchTestHandler.h index 4a5dac1d6..42f87bddd 100644 --- a/Source/CTest/cmCTestBatchTestHandler.h +++ b/Source/CTest/cmCTestBatchTestHandler.h @@ -3,7 +3,7 @@ #ifndef cmCTestBatchTestHandler_h #define cmCTestBatchTestHandler_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestMultiProcessHandler.h" #include "cmsys/FStream.hxx" @@ -17,8 +17,8 @@ class cmCTestBatchTestHandler : public cmCTestMultiProcessHandler { public: - ~cmCTestBatchTestHandler() CM_OVERRIDE; - void RunTests() CM_OVERRIDE; + ~cmCTestBatchTestHandler() override; + void RunTests() override; protected: void WriteBatchScript(); diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index cc290715c..a0d68a066 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -32,7 +32,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,7 +45,6 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring, std::string& cmakeOutString, cmake* cm) { - unsigned int k; std::vector args; args.push_back(cmSystemTools::GetCMakeCommand()); args.push_back(this->SourceDir); @@ -65,7 +64,7 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring, args.push_back(toolset); } - const char* config = CM_NULLPTR; + const char* config = nullptr; if (!this->CTest->GetConfigType().empty()) { config = this->CTest->GetConfigType().c_str(); } @@ -80,8 +79,8 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring, args.push_back(btype); } - 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"; @@ -115,21 +114,21 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring, void CMakeMessageCallback(const char* m, const char* /*unused*/, bool& /*unused*/, void* s) { - std::string* out = (std::string*)s; + std::string* out = static_cast(s); *out += m; *out += "\n"; } void CMakeProgressCallback(const char* msg, float /*unused*/, void* s) { - std::string* out = (std::string*)s; + std::string* out = static_cast(s); *out += msg; *out += "\n"; } void CMakeOutputCallback(const char* m, size_t len, void* s) { - std::string* out = (std::string*)s; + std::string* out = static_cast(s); out->append(m, len); } @@ -148,10 +147,10 @@ public: } ~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, nullptr); + cmSystemTools::SetStderrCallback(nullptr, nullptr); + cmSystemTools::SetStdoutCallback(nullptr, nullptr); + cmSystemTools::SetMessageCallback(nullptr, nullptr); } }; @@ -219,12 +218,10 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) } // do the build - std::vector::iterator tarIt; if (this->BuildTargets.empty()) { this->BuildTargets.push_back(""); } - for (tarIt = this->BuildTargets.begin(); tarIt != this->BuildTargets.end(); - ++tarIt) { + for (std::string const& tar : this->BuildTargets) { double remainingTime = 0; if (this->Timeout > 0) { remainingTime = this->Timeout - cmSystemTools::GetTime() + clock_start; @@ -236,7 +233,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,7 +246,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) config = "Debug"; } int retVal = cm.GetGlobalGenerator()->Build( - this->SourceDir, this->BinaryDir, this->BuildProject, *tarIt, output, + this->SourceDir, this->BinaryDir, this->BuildProject, tar, output, this->BuildMakeProgram, config, !this->BuildNoClean, false, false, remainingTime); out << output; @@ -292,8 +289,8 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) << 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,10 +302,10 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) std::vector 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 @@ -317,8 +314,8 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) cmSystemTools::ChangeDirectory(this->BuildRunDir); } 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"; @@ -334,8 +331,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"; diff --git a/Source/CTest/cmCTestBuildAndTestHandler.h b/Source/CTest/cmCTestBuildAndTestHandler.h index 2e85e9fed..f19cb67ce 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.h +++ b/Source/CTest/cmCTestBuildAndTestHandler.h @@ -3,7 +3,7 @@ #ifndef cmCTestBuildAndTestHandler_h #define cmCTestBuildAndTestHandler_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestGenericHandler.h" @@ -26,12 +26,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& allArgs) - CM_OVERRIDE; + int ProcessCommandLineArguments( + const std::string& currentArg, size_t& idx, + const std::vector& allArgs) override; /* * Get the output variable @@ -40,7 +40,7 @@ public: cmCTestBuildAndTestHandler(); - void Initialize() CM_OVERRIDE; + void Initialize() override; protected: ///! Run CMake and build a test and then run it as a single test. diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index 4c8276007..ce27da18a 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/Source/CTest/cmCTestBuildCommand.cxx @@ -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,7 +32,7 @@ cmCTestBuildCommand::~cmCTestBuildCommand() { if (this->GlobalGenerator) { delete this->GlobalGenerator; - this->GlobalGenerator = CM_NULLPTR; + this->GlobalGenerator = nullptr; } } @@ -41,9 +41,9 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler() cmCTestGenericHandler* handler = this->CTest->GetInitializedHandler("build"); if (!handler) { this->SetError("internal CTest error. Cannot instantiate build handler"); - return CM_NULLPTR; + return nullptr; } - this->Handler = (cmCTestBuildHandler*)handler; + this->Handler = static_cast(handler); const char* ctestBuildCommand = this->Makefile->GetDefinition("CTEST_BUILD_COMMAND"); @@ -89,7 +89,7 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler() if (this->GlobalGenerator) { if (this->GlobalGenerator->GetName() != cmakeGeneratorName) { delete this->GlobalGenerator; - this->GlobalGenerator = CM_NULLPTR; + this->GlobalGenerator = nullptr; } } if (!this->GlobalGenerator) { @@ -102,11 +102,11 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler() e += "\""; this->Makefile->IssueMessage(cmake::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 @@ -143,7 +143,7 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler() "with a custom command line."; /* clang-format on */ this->SetError(ostr.str()); - return CM_NULLPTR; + return nullptr; } } @@ -153,6 +153,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 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..f4fc76929 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -74,7 +74,7 @@ static const char* cmCTestErrorMatches[] = { "^The project cannot be built\\.", "^\\[ERROR\\]", "^Command .* failed with exit code", - CM_NULLPTR + nullptr }; static const char* cmCTestErrorExceptions[] = { @@ -89,7 +89,7 @@ static const char* cmCTestErrorExceptions[] = { ":[ \\t]+Where:", "([^ :]+):([0-9]+): Warning", "------ Build started: .* ------", - CM_NULLPTR + nullptr }; static const char* cmCTestWarningMatches[] = { @@ -114,7 +114,7 @@ static const char* cmCTestWarningMatches[] = { "cc-[0-9]* CC: REMARK File = .*, Line = [0-9]*", "^CMake Warning.*:", "^\\[WARNING\\]", - CM_NULLPTR + nullptr }; static const char* cmCTestWarningExceptions[] = { @@ -134,7 +134,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 @@ -152,7 +152,7 @@ static cmCTestBuildCompileErrorWarningRex cmCTestWarningErrorFileLine[] = { { "^([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 +171,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 +190,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 +260,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"; } @@ -350,18 +350,16 @@ int cmCTestBuildHandler::ProcessHandler() this->CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]); } - // Pre-compile regular expressions objects for all regular expressions - std::vector::iterator it; +// Pre-compile regular expressions objects for all regular expressions #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) { \ + for (std::string const& s : (strings)) { \ cmCTestOptionalLog(this->CTest, DEBUG, \ - "Add " #strings ": " << *it << std::endl, \ - this->Quiet); \ - (regexes).push_back(it->c_str()); \ + "Add " #strings ": " << s << std::endl, this->Quiet); \ + (regexes).push_back(s.c_str()); \ } cmCTestBuildHandlerPopulateRegexVector(this->CustomErrorMatches, this->ErrorMatchRegex); @@ -373,8 +371,8 @@ 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") + "/"; @@ -426,27 +424,24 @@ int cmCTestBuildHandler::ProcessHandler() double elapsed_build_time = cmSystemTools::GetTime() - elapsed_time_start; // Cleanups strings in the errors and warnings list. - t_ErrorsAndWarningsVector::iterator evit; if (!this->SimplifySourceDir.empty()) { - for (evit = this->ErrorsAndWarnings.begin(); - evit != this->ErrorsAndWarnings.end(); ++evit) { - cmSystemTools::ReplaceString(evit->Text, this->SimplifySourceDir.c_str(), + 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(), "/.../"); } } @@ -488,6 +483,7 @@ 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", @@ -503,7 +499,7 @@ public: { } FragmentCompare() - : FTC(CM_NULLPTR) + : FTC(nullptr) { } bool operator()(std::string const& l, std::string const& r) const @@ -555,9 +551,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 +582,11 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(cmXMLWriter& xml) xml.StartElement(cm->Error ? "Error" : "Warning"); xml.Element("BuildLogLine", cm->LogLine); xml.Element("Text", cm->Text); - std::vector::iterator rit; - for (rit = this->ErrorWarningFileLineRegex.begin(); - rit != this->ErrorWarningFileLineRegex.end(); ++rit) { - cmsys::RegularExpression* re = &rit->RegularExpression; + for (cmCTestCompileErrorWarningRex& rit : + this->ErrorWarningFileLineRegex) { + cmsys::RegularExpression* re = &rit.RegularExpression; if (re->find(cm->Text.c_str())) { - cm->SourceFile = re->match(rit->FileIndex); + 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 +602,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; } } @@ -758,9 +752,8 @@ void cmCTestBuildHandler::LaunchHelper::WriteScrapeMatchers( fname += purpose; fname += ".txt"; cmGeneratedFileStream fout(fname.c_str()); - for (std::vector::const_iterator mi = matchers.begin(); - mi != matchers.end(); ++mi) { - fout << *mi << "\n"; + for (std::string const& m : matchers) { + fout << m << "\n"; } } @@ -776,18 +769,20 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, } std::vector argv; - for (std::vector::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::iterator ait; - for (ait = argv.begin(); ait != argv.end() && *ait; ++ait) { + 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); @@ -834,7 +829,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,9 +860,9 @@ 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: " << ((this->BuildOutputLogSize + 512) / 1024) << "K" @@ -875,7 +870,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, 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,8 +889,8 @@ 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->TotalWarnings++; @@ -917,8 +912,8 @@ 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->TotalErrors++; @@ -1002,14 +997,12 @@ void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length, // This is an error or warning, so generate report errorwarning.LogLine = static_cast(this->OutputLineCounter + 1); errorwarning.Text = line; - errorwarning.PreContext = ""; - errorwarning.PostContext = ""; + errorwarning.PreContext.clear(); + errorwarning.PostContext.clear(); // Copy pre-context to report - std::deque::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(); @@ -1081,8 +1074,6 @@ int cmCTestBuildHandler::ProcessSingleLine(const char* data) cmCTestOptionalLog(this->CTest, DEBUG, "Line: [" << data << "]" << std::endl, this->Quiet); - std::vector::iterator it; - int warningLine = 0; int errorLine = 0; @@ -1091,9 +1082,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,9 +1096,8 @@ 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: " << data << " (matches: " @@ -1123,9 +1112,8 @@ 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: " << data << " (matches: " @@ -1139,9 +1127,8 @@ 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: " << data << " (matches: " diff --git a/Source/CTest/cmCTestBuildHandler.h b/Source/CTest/cmCTestBuildHandler.h index ef3cddf1b..6e71ad6ae 100644 --- a/Source/CTest/cmCTestBuildHandler.h +++ b/Source/CTest/cmCTestBuildHandler.h @@ -3,7 +3,7 @@ #ifndef cmCTestBuildHandler_h #define cmCTestBuildHandler_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestGenericHandler.h" @@ -31,16 +31,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; } diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx index fad360ba4..5779935aa 100644 --- a/Source/CTest/cmCTestCVS.cxx +++ b/Source/CTest/cmCTestCVS.cxx @@ -46,7 +46,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)); @@ -92,11 +92,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::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> "); @@ -133,7 +132,7 @@ private: SectionType Section; Revision Rev; - bool ProcessLine() CM_OVERRIDE + bool ProcessLine() override { if (this->Line == ("=======================================" "======================================")) { @@ -221,8 +220,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 +241,12 @@ void cmCTestCVS::WriteXMLDirectory(cmXMLWriter& xml, std::string const& path, // Load revisions and write an entry for each file in this directory. std::vector 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 +255,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 +268,8 @@ bool cmCTestCVS::WriteXMLUpdates(cmXMLWriter& xml) " " << std::flush); - for (std::map::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 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..c44b86605 100644 --- a/Source/CTest/cmCTestConfigureCommand.cxx +++ b/Source/CTest/cmCTestConfigureCommand.cxx @@ -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,7 +53,7 @@ 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"; @@ -61,7 +61,7 @@ cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler() 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::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,16 +132,22 @@ 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; } } + if (const char* labelsForSubprojects = + this->Makefile->GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) { + this->CTest->SetCTestConfiguration("LabelsForSubprojects", + labelsForSubprojects, this->Quiet); + } + cmCTestGenericHandler* handler = this->CTest->GetInitializedHandler("configure"); if (!handler) { this->SetError( "internal CTest error. Cannot instantiate configure handler"); - return CM_NULLPTR; + return nullptr; } 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..56a038e38 100644 --- a/Source/CTest/cmCTestConfigureHandler.cxx +++ b/Source/CTest/cmCTestConfigureHandler.cxx @@ -73,6 +73,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); 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..d2003baa3 100644 --- a/Source/CTest/cmCTestCoverageCommand.cxx +++ b/Source/CTest/cmCTestCoverageCommand.cxx @@ -23,7 +23,7 @@ cmCTestGenericHandler* cmCTestCoverageCommand::InitializeHandler() this->CTest->GetInitializedHandler("coverage")); if (!handler) { this->SetError("internal CTest error. Cannot instantiate test handler"); - return CM_NULLPTR; + return nullptr; } // If a LABELS option was given, select only files with the labels. 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..56eeceb0b 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -67,12 +67,10 @@ public: bool StartProcess() { std::vector args; - for (std::vector::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 + args.push_back(nullptr); // null terminate cmsysProcess_SetCommand(this->Process, &*args.begin()); if (!this->WorkingDirectory.empty()) { cmsysProcess_SetWorkingDirectory(this->Process, @@ -97,7 +95,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; @@ -136,10 +134,9 @@ void cmCTestCoverageHandler::CleanCoverageLogFiles(std::ostream& log) cmsys::Glob gl; gl.FindFiles(logGlob); std::vector const& files = gl.GetFiles(); - for (std::vector::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); } } @@ -188,18 +185,16 @@ void cmCTestCoverageHandler::EndCoverageLogXML(cmXMLWriter& xml) 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::iterator sit; - for (sit = this->CustomCoverageExcludeRegex.begin(); - sit != this->CustomCoverageExcludeRegex.end(); ++sit) { - if (sit->find(file)) { + 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; @@ -319,11 +314,9 @@ int cmCTestCoverageHandler::ProcessHandler() // setup the regex exclude stuff this->CustomCoverageExcludeRegex.clear(); - std::vector::iterator rexIt; - for (rexIt = this->CustomCoverageExclude.begin(); - rexIt != this->CustomCoverageExclude.end(); ++rexIt) { + for (std::string const& rex : this->CustomCoverageExclude) { this->CustomCoverageExcludeRegex.push_back( - cmsys::RegularExpression(rexIt->c_str())); + cmsys::RegularExpression(rex.c_str())); } if (this->HandleBullseyeCoverage(&cont)) { @@ -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,8 +422,7 @@ int cmCTestCoverageHandler::ProcessHandler() std::vector 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++; @@ -443,9 +434,9 @@ int cmCTestCoverageHandler::ProcessHandler() 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: " @@ -478,7 +469,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); @@ -554,14 +545,13 @@ int cmCTestCoverageHandler::ProcessHandler() } // Handle all the files in the extra coverage globs that have no cov data - for (std::set::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 +567,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 +583,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 +600,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::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); } } @@ -670,17 +658,14 @@ void cmCTestCoverageHandler::PopulateCustomVectors(cmMakefile* mf) this->CustomCoverageExclude); this->CTest->PopulateCustomVector(mf, "CTEST_EXTRA_COVERAGE_GLOB", this->ExtraCoverageGlobs); - std::vector::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); } } @@ -877,6 +862,24 @@ int cmCTestCoverageHandler::HandleDelphiCoverage( return static_cast(cont->TotalCoverage.size()); } +static std::string joinCommandLine(const std::vector& 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 @@ -961,7 +964,6 @@ int cmCTestCoverageHandler::HandleGCovCoverage( std::vector files; this->FindGCovFiles(files); - std::vector::iterator it; if (files.empty()) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, @@ -992,19 +994,26 @@ int cmCTestCoverageHandler::HandleGCovCoverage( cmCTestCoverageHandlerLocale locale_C; static_cast(locale_C); + std::vector basecovargs = + cmSystemTools::ParseArguments(gcovExtraFlags.c_str()); + basecovargs.insert(basecovargs.begin(), gcovCommand); + basecovargs.push_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 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,15 +1023,14 @@ 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(), 0 /*this->TimeOut*/); *cont->OFS << " Output: " << output << std::endl; *cont->OFS << " Errors: " << errors << std::endl; if (!res) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem running coverage on file: " << *it << std::endl); + "Problem running coverage on file: " << f << std::endl); cmCTestLog(this->CTest, ERROR_MESSAGE, "Command produced error: " << errors << std::endl); cont->Error++; @@ -1030,7 +1038,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } if (retVal != 0) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Coverage command returned: " - << retVal << " while processing: " << *it << std::endl); + << retVal << " while processing: " << f << std::endl); cmCTestLog(this->CTest, ERROR_MESSAGE, "Command produced error: " << cont->Error << std::endl); } @@ -1044,20 +1052,19 @@ int cmCTestCoverageHandler::HandleGCovCoverage( this->Quiet); std::vector lines; - std::vector::iterator line; cmSystemTools::Split(output.c_str(), 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.c_str())) { if (gcovStyle == 0) { gcovStyle = 1; } @@ -1068,9 +1075,9 @@ int cmCTestCoverageHandler::HandleGCovCoverage( break; } - actualSourceFile = ""; + actualSourceFile.clear(); sourceFile = st1re1.match(2); - } else if (st1re2.find(line->c_str())) { + } else if (st1re2.find(line.c_str())) { if (gcovStyle == 0) { gcovStyle = 1; } @@ -1082,7 +1089,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } gcovFile = st1re2.match(1); - } else if (st2re1.find(line->c_str())) { + } else if (st2re1.find(line.c_str())) { if (gcovStyle == 0) { gcovStyle = 2; } @@ -1093,9 +1100,9 @@ int cmCTestCoverageHandler::HandleGCovCoverage( break; } - actualSourceFile = ""; + actualSourceFile.clear(); sourceFile = st2re1.match(1); - } else if (st2re2.find(line->c_str())) { + } else if (st2re2.find(line.c_str())) { if (gcovStyle == 0) { gcovStyle = 2; } @@ -1105,7 +1112,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( cont->Error++; break; } - } else if (st2re3.find(line->c_str())) { + } else if (st2re3.find(line.c_str())) { if (gcovStyle == 0) { gcovStyle = 2; } @@ -1117,7 +1124,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } gcovFile = st2re3.match(2); - } else if (st2re4.find(line->c_str())) { + } else if (st2re4.find(line.c_str())) { if (gcovStyle == 0) { gcovStyle = 2; } @@ -1132,7 +1139,7 @@ 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.c_str())) { if (gcovStyle == 0) { gcovStyle = 2; } @@ -1146,7 +1153,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( 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.c_str())) { if (gcovStyle == 0) { gcovStyle = 2; } @@ -1164,10 +1171,10 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } 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 ")) { + if (line != "No executable lines" && + !cmSystemTools::StringStartsWith(line.c_str(), "Removing ")) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output line: [" - << *line << "]" << std::endl); + << line << "]" << std::endl); cont->Error++; // abort(); } @@ -1235,11 +1242,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 +1339,6 @@ int cmCTestCoverageHandler::HandleLCovCoverage( "Error while finding LCov files.\n"); return 0; } - std::vector::iterator it; if (files.empty()) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, @@ -1357,14 +1363,18 @@ int cmCTestCoverageHandler::HandleLCovCoverage( cmCTestCoverageHandlerLocale locale_C; static_cast(locale_C); + std::vector covargs = + cmSystemTools::ParseArguments(lcovExtraFlags.c_str()); + 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 + " "; cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Current coverage dir: " << fileDir << std::endl, @@ -1377,15 +1387,14 @@ 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(), 0 /*this->TimeOut*/); *cont->OFS << " Output: " << output << std::endl; *cont->OFS << " Errors: " << errors << std::endl; if (!res) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem running coverage on file: " << *it << std::endl); + "Problem running coverage on file: " << f << std::endl); cmCTestLog(this->CTest, ERROR_MESSAGE, "Command produced error: " << errors << std::endl); cont->Error++; @@ -1393,7 +1402,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage( } if (retVal != 0) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Coverage command returned: " - << retVal << " while processing: " << *it << std::endl); + << retVal << " while processing: " << f << std::endl); cmCTestLog(this->CTest, ERROR_MESSAGE, "Command produced error: " << cont->Error << std::endl); } @@ -1407,15 +1416,14 @@ int cmCTestCoverageHandler::HandleLCovCoverage( this->Quiet); std::vector lines; - std::vector::iterator line; cmSystemTools::Split(output.c_str(), 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 @@ -1438,9 +1446,8 @@ int cmCTestCoverageHandler::HandleLCovCoverage( lcovFiles.insert(lcovFiles.end(), gl.GetFiles().begin(), gl.GetFiles().end()); - for (std::vector::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 +1469,9 @@ int cmCTestCoverageHandler::HandleLCovCoverage( sourceFile = srcname; actualSourceFile = srcname; - for (std::vector::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 +1543,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage( } } - actualSourceFile = ""; + actualSourceFile.clear(); } } } @@ -1562,10 +1568,9 @@ void cmCTestCoverageHandler::FindGCovFiles(std::vector& 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,12 +1578,12 @@ void cmCTestCoverageHandler::FindGCovFiles(std::vector& 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; + daGlob = lm.first; daGlob += "/*.gcda"; gl.FindFiles(daGlob); files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end()); @@ -1641,14 +1646,13 @@ int cmCTestCoverageHandler::HandleTracePyCoverage( std::string tempDir = testingDir + "/CoverageInfo"; cmSystemTools::MakeDirectory(tempDir.c_str()); - std::vector::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 +1664,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; @@ -1761,7 +1765,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,7 +1793,7 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch( cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "run covbr: " << std::endl, this->Quiet); - if (!this->RunBullseyeCommand(cont, "covbr", CM_NULLPTR, outputFile)) { + if (!this->RunBullseyeCommand(cont, "covbr", nullptr, outputFile)) { cmCTestLog(this->CTest, ERROR_MESSAGE, "error running covbr for." << "\n"); return -1; @@ -1862,7 +1866,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); @@ -2014,8 +2018,8 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary( 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, @@ -2256,9 +2260,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 +2271,8 @@ void cmCTestCoverageHandler::SetLabelFilter( std::set const& labels) { this->LabelFilter.clear(); - for (std::set::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 +2312,23 @@ std::set cmCTestCoverageHandler::FindUncoveredFiles( { std::set extraMatches; - for (std::vector::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 files = gl.GetFiles(); - for (std::vector::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 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..7b5ea6005 100644 --- a/Source/CTest/cmCTestCurl.cxx +++ b/Source/CTest/cmCTestCurl.cxx @@ -5,7 +5,6 @@ #include "cmCTest.h" #include "cmSystemTools.h" -#include "cmConfigure.h" #include #include @@ -42,7 +41,7 @@ namespace { size_t curlWriteMemoryCallback(void* ptr, size_t size, size_t nmemb, void* data) { - int realsize = (int)(size * nmemb); + int realsize = static_cast(size * nmemb); std::vector* vec = static_cast*>(data); const char* chPtr = static_cast(ptr); @@ -62,12 +61,11 @@ size_t curlDebugCallback(CURL* /*unused*/, curl_infotype /*unused*/, void cmCTestCurl::SetCurlOptions(std::vector const& args) { - for (std::vector::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; } } @@ -111,7 +109,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 +143,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::const_iterator h = this->HttpHeaders.begin(); - h != this->HttpHeaders.end(); ++h) { + for (std::string const& h : this->HttpHeaders) { cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Add HTTP Header: \"" << *h << "\"" << std::endl, + " 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 responseData; std::vector 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); @@ -188,7 +185,7 @@ bool cmCTestCurl::UploadFile(std::string const& local_file, bool cmCTestCurl::HttpRequest(std::string const& url, std::string const& fields, std::string& response) { - response = ""; + response.clear(); cmCTestOptionalLog(this->CTest, DEBUG, "HttpRequest\n" << "url: " << url << "\n" << "fields " << fields << "\n", @@ -207,20 +204,18 @@ bool cmCTestCurl::HttpRequest(std::string const& url, ::curl_easy_setopt(this->Curl, CURLOPT_DEBUGFUNCTION, curlDebugCallback); std::vector responseData; std::vector 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::const_iterator h = - this->HttpHeaders.begin(); - h != this->HttpHeaders.end(); ++h) { + for (std::string const& h : this->HttpHeaders) { cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Add HTTP Header: \"" << *h << "\"" << std::endl, + " 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 +240,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/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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 230aedf3b..8cb795e22 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -46,7 +46,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 +58,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> "); @@ -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; } @@ -118,7 +118,7 @@ std::string cmCTestGIT::FindGitDir() 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 += "/"; @@ -164,13 +163,12 @@ bool cmCTestGIT::UpdateByFetchAndReset() opts = this->CTest->GetCTestConfiguration("GITUpdateOptions"); } std::vector args = cmSystemTools::ParseArguments(opts.c_str()); - for (std::vector::const_iterator ai = args.begin(); - ai != args.end(); ++ai) { - git_fetch.push_back(ai->c_str()); + 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 git_custom_command; cmSystemTools::ExpandListArgument(custom, git_custom_command, true); std::vector git_custom; - for (std::vector::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,7 +247,7 @@ 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())) { this->Log << "Git < 1.6.5 cannot update submodules recursively\n"; @@ -259,7 +256,7 @@ bool cmCTestGIT::UpdateImpl() // 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())) { this->Log << "Git < 1.8.1 cannot synchronize submodules recursively\n"; @@ -274,8 +271,7 @@ 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 }; + 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; @@ -513,11 +509,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(&c), 10); + person.TimeZone = strtol(c, const_cast(&c), 10); } - bool ProcessLine() CM_OVERRIDE + bool ProcessLine() override { if (this->Line.empty()) { if (this->Section == SectionBody && this->LineEnd == '\0') { @@ -615,10 +611,10 @@ 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"; @@ -645,23 +641,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::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..ce8f70998 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 #include @@ -12,7 +11,7 @@ cmCTestGenericHandler::cmCTestGenericHandler() { this->HandlerVerbose = cmSystemTools::OUTPUT_NONE; - this->CTest = CM_NULLPTR; + this->CTest = nullptr; this->SubmitIndex = 0; this->AppendXML = false; this->Quiet = false; @@ -58,10 +57,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 +67,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(); } diff --git a/Source/CTest/cmCTestGlobalVC.cxx b/Source/CTest/cmCTestGlobalVC.cxx index 25294b5ae..d2714d90b 100644 --- a/Source/CTest/cmCTestGlobalVC.cxx +++ b/Source/CTest/cmCTestGlobalVC.cxx @@ -48,15 +48,14 @@ void cmCTestGlobalVC::DoRevision(Revision const& revision, /* clang-format on */ // Update information about revisions of the changed files. - for (std::vector::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 +82,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,10 +113,8 @@ bool cmCTestGlobalVC::WriteXMLUpdates(cmXMLWriter& xml) this->WriteXMLGlobal(xml); - for (std::map::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; diff --git a/Source/CTest/cmCTestGlobalVC.h b/Source/CTest/cmCTestGlobalVC.h index a5273d3dd..76377ed17 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,11 @@ 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; /** 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..525dacc1d 100644 --- a/Source/CTest/cmCTestHG.cxx +++ b/Source/CTest/cmCTestHG.cxx @@ -36,7 +36,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 +60,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 +96,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> "); @@ -126,7 +126,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); @@ -145,13 +145,12 @@ bool cmCTestHG::UpdateImpl() opts = this->CTest->GetCTestConfiguration("HGUpdateOptions"); } std::vector args = cmSystemTools::ParseArguments(opts.c_str()); - for (std::vector::const_iterator ai = args.begin(); - ai != args.end(); ++ai) { - hg_update.push_back(ai->c_str()); + 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> "); @@ -168,7 +167,7 @@ public: { this->InitializeParser(); } - ~LogParser() CM_OVERRIDE { this->CleanupParser(); } + ~LogParser() override { this->CleanupParser(); } private: cmCTestHG* HG; @@ -179,14 +178,14 @@ private: Change CurChange; std::vector 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") { @@ -198,12 +197,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); } - 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 +216,25 @@ private: this->Rev.Log.assign(&this->CData[0], this->CData.size()); } else if (!this->CData.empty() && name == "files") { std::vector 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 +245,19 @@ private: { std::vector 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 +285,7 @@ bool cmCTestHG::LoadRevisions() "\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 +301,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..5a7baf545 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -20,7 +20,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"; @@ -89,7 +89,7 @@ bool cmCTestHandlerCommand::InitialPass(std::vector 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 +97,11 @@ bool cmCTestHandlerCommand::InitialPass(std::vector 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; } 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; enum { diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 5b213518a..a1249f5b3 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 +#include // IWYU pragma: keep #include #include @@ -19,7 +18,6 @@ #include "cmStateSnapshot.h" #include "cmSystemTools.h" #include "cmXMLWriter.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #ifdef _WIN32 @@ -31,7 +29,7 @@ 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 +127,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; } @@ -171,9 +169,8 @@ void cmCTestLaunch::ComputeFileNames() cmCryptoHash md5(cmCryptoHash::AlgoMD5); md5.Initialize(); md5.Append(this->CWD); - for (std::vector::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 +221,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 +251,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); } @@ -396,7 +393,7 @@ void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml) } // OutputType - const char* outputType = CM_NULLPTR; + const char* outputType = nullptr; if (!this->OptionTargetType.empty()) { if (this->OptionTargetType == "EXECUTABLE") { outputType = "executable"; @@ -424,9 +421,8 @@ void cmCTestLaunch::WriteXMLCommand(cmXMLWriter& xml) if (!this->CWD.empty()) { xml.Element("WorkingDirectory", this->CWD); } - for (std::vector::const_iterator ai = this->RealArgs.begin(); - ai != this->RealArgs.end(); ++ai) { - xml.Element("Argument", *ai); + for (std::string const& realArg : this->RealArgs) { + xml.Element("Argument", realArg); } xml.EndElement(); // Command } @@ -489,9 +485,8 @@ void cmCTestLaunch::WriteXMLLabels(cmXMLWriter& xml) if (!this->Labels.empty()) { xml.Comment("Interested parties"); xml.StartElement("Labels"); - for (std::set::const_iterator li = this->Labels.begin(); - li != this->Labels.end(); ++li) { - xml.Element("Label", *li); + for (std::string const& label : this->Labels) { + xml.Element("Label", label); } xml.EndElement(); // Labels } @@ -508,7 +503,11 @@ void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml, std::string const& fname) if (MatchesFilterPrefix(line)) { continue; } - + if (this->Match(line, this->RegexWarningSuppress)) { + line = "[CTest: warning suppressed] " + line; + } else if (this->Match(line, this->RegexWarning)) { + line = "[CTest: warning matched] " + line; + } xml.Content(sep); xml.Content(line); sep = "\n"; @@ -595,9 +594,8 @@ bool cmCTestLaunch::ScrapeLog(std::string const& fname) bool cmCTestLaunch::Match(std::string const& line, std::vector& regexps) { - for (std::vector::iterator ri = regexps.begin(); - ri != regexps.end(); ++ri) { - if (ri->find(line.c_str())) { + for (cmsys::RegularExpression& r : regexps) { + if (r.find(line.c_str())) { return true; } } @@ -628,12 +626,12 @@ void cmCTestLaunch::LoadConfig() cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR 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"); + mf.ReadListFile(fname.c_str())) { + this->SourceDir = mf.GetSafeDefinition("CTEST_SOURCE_DIRECTORY"); cmSystemTools::ConvertToUnixSlashes(this->SourceDir); } } diff --git a/Source/CTest/cmCTestMemCheckCommand.cxx b/Source/CTest/cmCTestMemCheckCommand.cxx index b9cae3bfe..a5d599583 100644 --- a/Source/CTest/cmCTestMemCheckCommand.cxx +++ b/Source/CTest/cmCTestMemCheckCommand.cxx @@ -14,7 +14,7 @@ cmCTestMemCheckCommand::cmCTestMemCheckCommand() { this->Arguments[ctm_DEFECT_COUNT] = "DEFECT_COUNT"; - this->Arguments[ctm_LAST] = CM_NULLPTR; + this->Arguments[ctm_LAST] = nullptr; this->Last = ctm_LAST; } 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..3efb039ea 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -28,12 +28,12 @@ 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; + cmCTest* ctest = static_cast(data); cmCTestLog(ctest, ERROR_MESSAGE, "Error parsing XML in stream at line " << line << ": " << msg << std::endl); } @@ -45,9 +45,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 +58,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 +122,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 +157,13 @@ int cmCTestMemCheckHandler::PostProcessHandler() void cmCTestMemCheckHandler::GenerateTestCommand( std::vector& args, int test) { - std::vector::size_type pp; std::string index; std::ostringstream stream; std::string memcheckcommand = cmSystemTools::ConvertToOutputPath(this->MemoryTester.c_str()); stream << test; index = stream.str(); - for (pp = 0; pp < this->MemoryTesterDynamicOptions.size(); pp++) { - std::string arg = this->MemoryTesterDynamicOptions[pp]; + for (std::string arg : this->MemoryTesterDynamicOptions) { std::string::size_type pos = arg.find("??"); if (pos != std::string::npos) { arg.replace(pos, 2, index); @@ -180,18 +178,18 @@ void cmCTestMemCheckHandler::GenerateTestCommand( // via environment varaibles. 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 +226,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,10 +253,10 @@ 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) { + for (int i = 0; cmCTestMemCheckResultStrings[i] != nullptr; ++i) { this->ResultStrings.push_back(cmCTestMemCheckResultStrings[i]); this->ResultStringsLong.push_back(cmCTestMemCheckResultLongStrings[i]); this->GlobalResults.push_back(0); @@ -291,6 +289,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 +324,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 +333,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 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,11 +361,11 @@ 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 + << result.TestCount << ": " << outname << " Defects: " << memoryErrors << std::endl, this->Quiet); } @@ -419,8 +417,8 @@ 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())) { @@ -727,13 +725,12 @@ bool cmCTestMemCheckHandler::ProcessMemCheckSanitizerOutput( std::vector lines; cmSystemTools::Split(str.c_str(), lines); std::ostringstream ostr; - log = ""; - for (std::vector::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 +743,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckSanitizerOutput( defects++; ostr << "" << this->ResultStrings[idx] << " "; } - ostr << *i << std::endl; + ostr << l << std::endl; } log = ostr.str(); this->DefectCount += defects; @@ -758,16 +755,15 @@ bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput( std::vector lines; cmSystemTools::Split(str.c_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::iterator i = lines.begin(); i != lines.end(); - ++i) { + for (std::string const& l : lines) { std::vector::size_type failure = this->ResultStrings.size(); - if (pfW.find(*i)) { + if (pfW.find(l)) { std::vector::size_type cc; for (cc = 0; cc < this->ResultStrings.size(); cc++) { if (pfW.match(1) == this->ResultStrings[cc]) { @@ -787,7 +783,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput( results[failure]++; defects++; } - ostr << *i << std::endl; + ostr << l << std::endl; } log = ostr.str(); @@ -809,7 +805,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( std::string::size_type cc; std::ostringstream ostr; - log = ""; + log.clear(); int defects = 0; @@ -907,11 +903,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::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(this->CustomMaximumFailedTestOutputSize)) { @@ -934,7 +928,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput( const std::string& str, std::string& log, std::vector& results) { - log = ""; + log.clear(); double sttime = cmSystemTools::GetTime(); std::vector lines; cmSystemTools::Split(str.c_str(), lines); @@ -962,8 +956,8 @@ 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: " @@ -990,9 +984,8 @@ void cmCTestMemCheckHandler::PostProcessTest(cmCTestTestResult& res, int test) } else { std::vector files; this->TestOutputFileNames(test, files); - for (std::vector::iterator i = files.begin(); - i != files.end(); ++i) { - this->AppendMemTesterOutput(res, *i); + for (std::string const& f : files) { + this->AppendMemTesterOutput(res, f); } } } @@ -1086,7 +1079,7 @@ void cmCTestMemCheckHandler::TestOutputFileNames( if (g.GetFiles().empty()) { std::string log = "Cannot find memory tester output file: " + ofile; cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl); - ofile = ""; + ofile.clear(); } else { files = g.GetFiles(); return; @@ -1094,7 +1087,7 @@ void cmCTestMemCheckHandler::TestOutputFileNames( } else if (!cmSystemTools::FileExists(ofile.c_str())) { std::string log = "Cannot find memory tester output file: " + ofile; cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl); - ofile = ""; + ofile.clear(); } files.push_back(ofile); } diff --git a/Source/CTest/cmCTestMemCheckHandler.h b/Source/CTest/cmCTestMemCheckHandler.h index 333c2e2dd..921829429 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& args, - int test) CM_OVERRIDE; + int PreProcessHandler() override; + int PostProcessHandler() override; + void GenerateTestCommand(std::vector& args, int test) override; private: enum @@ -121,7 +120,7 @@ private: /** * Generate the Dart compatible output */ - void GenerateDartOutput(cmXMLWriter& xml) CM_OVERRIDE; + void GenerateDartOutput(cmXMLWriter& xml) override; std::vector CustomPreMemCheck; std::vector CustomPostMemCheck; diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 2c16a0d1e..6a7bdc03e 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -64,10 +64,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(); @@ -131,11 +130,10 @@ 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::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); } } @@ -152,9 +150,8 @@ void cmCTestMultiProcessHandler::StartTestProcess(int test) return; } else { - for (TestMap::iterator j = this->Tests.begin(); j != this->Tests.end(); - ++j) { - j->second.erase(test); + for (auto& j : this->Tests) { + j.second.erase(test); } this->UnlockResources(test); @@ -183,10 +180,8 @@ void cmCTestMultiProcessHandler::LockResources(int index) void cmCTestMultiProcessHandler::UnlockResources(int index) { - for (std::set::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; @@ -219,10 +214,8 @@ std::string cmCTestMultiProcessHandler::GetName(int test) bool cmCTestMultiProcessHandler::StartTest(int test) { // Check for locked resources - for (std::set::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; } } @@ -292,22 +285,22 @@ 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 + << GetName(test) << ", it requires " << processors << " procs & system load is: " << systemLoad << std::endl); allTestsFailedTestLoadCheck = false; @@ -318,10 +311,10 @@ void cmCTestMultiProcessHandler::StartNextTests() if (processors <= minProcessorsRequired) { minProcessorsRequired = processors; - testWithMinProcessors = GetName(*test); + testWithMinProcessors = GetName(test); } - if (testLoadOk && processors <= numToStart && this->StartTest(*test)) { + if (testLoadOk && processors <= numToStart && this->StartTest(test)) { if (this->StopTimePassed) { return; } @@ -368,18 +361,13 @@ bool cmCTestMultiProcessHandler::CheckOutput() } std::vector finished; std::string out, err; - for (std::set::const_iterator i = - this->RunningTests.begin(); - i != this->RunningTests.end(); ++i) { - cmCTestRunTest* p = *i; + for (cmCTestRunTest* p : this->RunningTests) { if (!p->CheckOutput()) { finished.push_back(p); } } - for (std::vector::iterator i = finished.begin(); - i != finished.end(); ++i) { + for (cmCTestRunTest* p : finished) { this->Completed++; - cmCTestRunTest* p = *i; int test = p->GetIndex(); bool testResult = p->EndTest(this->Completed, this->Total, true); @@ -392,9 +380,8 @@ bool cmCTestMultiProcessHandler::CheckOutput() } else { this->Failed->push_back(p->GetTestProperties()->Name); } - for (TestMap::iterator j = this->Tests.begin(); j != this->Tests.end(); - ++j) { - j->second.erase(test); + for (auto& t : this->Tests) { + t.second.erase(test); } this->TestFinishMap[test] = true; this->TestRunningMap[test] = false; @@ -451,16 +438,15 @@ 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::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()); @@ -505,7 +491,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 +503,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; @@ -545,16 +530,15 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList() // 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); } } @@ -566,15 +550,13 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList() priorityStack.push_back(TestSet()); TestSet& currentSet = priorityStack.back(); - for (TestSet::const_iterator i = previousSet.begin(); - i != previousSet.end(); ++i) { - TestSet const& dependencies = this->Tests[*i]; + for (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); } } @@ -594,11 +576,10 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList() 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); + for (auto const& j : sortedCopy) { + if (alreadySortedTests.find(j) == alreadySortedTests.end()) { + this->SortedTests.push_back(j); + alreadySortedTests.insert(j); } } } @@ -608,10 +589,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,9 +599,8 @@ 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); @@ -629,10 +608,7 @@ void cmCTestMultiProcessHandler::CreateSerialTestCostList() 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 +616,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); @@ -679,10 +652,9 @@ void cmCTestMultiProcessHandler::PrintTestList() 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; cmWorkingDirectory workdir(p.Directory); @@ -696,9 +668,8 @@ void cmCTestMultiProcessHandler::PrintTestList() cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Labels:", this->Quiet); } - for (std::vector::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 @@ -737,9 +708,8 @@ void cmCTestMultiProcessHandler::PrintTestList() void cmCTestMultiProcessHandler::PrintLabels() { std::set 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 +720,9 @@ void cmCTestMultiProcessHandler::PrintLabels() cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "No Labels Exist" << std::endl, this->Quiet); } - for (std::set::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); } } @@ -794,10 +763,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 +777,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 visited; std::stack s; s.push(root); @@ -820,9 +787,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 +798,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/cmCTestP4.cxx b/Source/CTest/cmCTestP4.cxx index c80221634..fdf893243 100644 --- a/Source/CTest/cmCTestP4.cxx +++ b/Source/CTest/cmCTestP4.cxx @@ -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> "); @@ -217,7 +217,7 @@ private: SectionType Section; Revision Rev; - bool ProcessLine() CM_OVERRIDE + bool ProcessLine() override { if (this->Line.empty()) { this->NextSection(); @@ -332,9 +332,8 @@ void cmCTestP4::SetP4Options(std::vector& CommandOptions) } CommandOptions.clear(); - for (std::vector::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 +349,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); @@ -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> "); @@ -431,7 +430,7 @@ bool cmCTestP4::LoadRevisions() 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(nullptr); DescribeParser outDescribe(this, "p4_describe-out> "); OutputLogger errDescribe(this->Log, "p4_describe-err> "); @@ -451,7 +450,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 +464,11 @@ bool cmCTestP4::UpdateCustom(const std::string& custom) cmSystemTools::ExpandListArgument(custom, p4_custom_command, true); std::vector p4_custom; - for (std::vector::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> "); @@ -502,9 +501,8 @@ bool cmCTestP4::UpdateImpl() opts = this->CTest->GetCTestConfiguration("P4UpdateOptions"); } std::vector args = cmSystemTools::ParseArguments(opts.c_str()); - for (std::vector::const_iterator ai = args.begin(); - ai != args.end(); ++ai) { - p4_sync.push_back(ai->c_str()); + for (std::string const& arg : args) { + p4_sync.push_back(arg.c_str()); } std::string source = this->SourceDirectory + "/..."; @@ -520,7 +518,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 ChangeLists; @@ -51,13 +51,13 @@ private: void SetP4Options(std::vector& 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::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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 0c4269e3d..abdb6433f 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -9,7 +9,6 @@ #include "cmSystemTools.h" #include "cmWorkingDirectory.h" -#include "cmConfigure.h" #include "cm_curl.h" #include "cm_zlib.h" #include "cmsys/Base64.h" @@ -25,14 +24,14 @@ cmCTestRunTest::cmCTestRunTest(cmCTestTestHandler* handler) { this->CTest = handler->CTest; this->TestHandler = handler; - this->TestProcess = CM_NULLPTR; + this->TestProcess = nullptr; this->TestResult.ExecutionTime = 0; this->TestResult.ReturnValue = 0; this->TestResult.Status = cmCTestTestHandler::NOT_RUN; this->TestResult.TestCount = 0; - this->TestResult.Properties = CM_NULLPTR; - this->ProcessOutput = ""; - this->CompressedOutput = ""; + this->TestResult.Properties = nullptr; + this->ProcessOutput.clear(); + this->CompressedOutput.clear(); this->CompressionRatio = 2; this->StopTimePassed = false; this->NumberOfRunsLeft = 1; // default to 1 run of the test @@ -65,12 +64,8 @@ bool cmCTestRunTest::CheckOutput() // Check for TIMEOUT_AFTER_MATCH property. if (!this->TestProperties->TimeoutRegularExpressions.empty()) { - std::vector< - std::pair >::iterator regIt; - for (regIt = this->TestProperties->TimeoutRegularExpressions.begin(); - regIt != this->TestProperties->TimeoutRegularExpressions.end(); - ++regIt) { - if (regIt->first.find(this->ProcessOutput.c_str())) { + for (auto& reg : this->TestProperties->TimeoutRegularExpressions) { + if (reg.first.find(this->ProcessOutput.c_str())) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->GetIndex() << ": " << "Test timeout changed to " @@ -164,18 +159,14 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) int res = started ? this->TestProcess->GetProcessStatus() : cmsysProcess_State_Error; int retVal = this->TestProcess->GetExitValue(); - std::vector >::iterator - passIt; 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.c_str())) { found = true; reason = "Required regular expression found."; break; @@ -186,23 +177,19 @@ 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.c_str())) { reason = "Error regular expression found in output."; reason += " Regex=["; - reason += passIt->second; + reason += pass.second; reason += "]"; forceFail = true; break; @@ -237,6 +224,8 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) } else if (res == cmsysProcess_State_Exception) { outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure; cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: "); + this->TestResult.ExceptionStatus = + this->TestProcess->GetExitExceptionString(); switch (this->TestProcess->GetExitException()) { case cmsysProcess_Exception_Fault: cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault"); @@ -255,7 +244,8 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) 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) { @@ -436,7 +426,7 @@ bool cmCTestRunTest::StartTest(size_t total) this->TestResult.Path = this->TestProperties->Directory; this->TestProcess = new cmProcess; this->TestResult.Output = "Disabled"; - this->TestResult.FullCommandLine = ""; + this->TestResult.FullCommandLine.clear(); return false; } @@ -455,15 +445,13 @@ bool cmCTestRunTest::StartTest(size_t total) if (!this->FailedDependencies.empty()) { this->TestProcess = new cmProcess; std::string msg = "Failed test dependencies:"; - for (std::set::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; @@ -483,18 +471,14 @@ 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::iterator i = - this->TestProperties->RequiredFiles.begin(); - i != this->TestProperties->RequiredFiles.end(); ++i) { - std::string file = *i; - + for (std::string const& file : this->TestProperties->RequiredFiles) { if (!cmSystemTools::FileExists(file.c_str())) { // Required file was not found this->TestProcess = new cmProcess; @@ -503,14 +487,14 @@ bool cmCTestRunTest::StartTest(size_t total) 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; @@ -519,7 +503,7 @@ bool cmCTestRunTest::StartTest(size_t total) 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; @@ -558,10 +542,9 @@ void cmCTestRunTest::ComputeArguments() // Prepends memcheck args to our command string this->TestHandler->GenerateTestCommand(this->Arguments, this->Index); - for (std::vector::iterator i = this->Arguments.begin(); - i != this->Arguments.end(); ++i) { + for (std::string const& arg : this->Arguments) { testCommand += " \""; - testCommand += *i; + testCommand += arg; testCommand += "\""; } @@ -585,10 +568,8 @@ void cmCTestRunTest::ComputeArguments() << ": " << "Environment variables: " << std::endl); } - for (std::vector::const_iterator e = - this->TestProperties->Environment.begin(); - e != this->TestProperties->Environment.end(); ++e) { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index << ": " << *e + for (std::string const& env : this->TestProperties->Environment) { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index << ": " << env << std::endl); } } @@ -614,11 +595,11 @@ double cmCTestRunTest::ResolveTimeout() { double timeout = this->TestProperties->Timeout; - if (this->CTest->GetStopTime() == "") { + if (this->CTest->GetStopTime().empty()) { return timeout; } struct tm* lctime; - time_t current_time = time(CM_NULLPTR); + time_t current_time = time(nullptr); lctime = gmtime(¤t_time); int gm_hour = lctime->tm_hour; time_t gm_time = mktime(lctime); @@ -762,9 +743,8 @@ void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total) << std::endl; *this->TestHandler->LogFile << "Command: \"" << this->ActualCommand << "\""; - for (std::vector::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 diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx index f60f78c21..ce9622492 100644 --- a/Source/CTest/cmCTestSVN.cxx +++ b/Source/CTest/cmCTestSVN.cxx @@ -59,7 +59,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,10 +103,7 @@ bool cmCTestSVN::NoteOldRevision() return false; } - std::vector::iterator itbeg = this->Repositories.begin(); - std::vector::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"; @@ -127,10 +124,7 @@ bool cmCTestSVN::NoteNewRevision() return false; } - std::vector::iterator itbeg = this->Repositories.begin(); - std::vector::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"; @@ -205,7 +199,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], @@ -257,9 +251,8 @@ bool cmCTestSVN::UpdateImpl() std::vector svn_update; svn_update.push_back("update"); - for (std::vector::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> "); @@ -285,12 +278,11 @@ bool cmCTestSVN::RunSVNCommand(std::vector const& parameters, std::vector parsedUserOptions = cmSystemTools::ParseArguments(userOptions.c_str()); - for (std::vector::iterator i = parsedUserOptions.begin(); - i != parsedUserOptions.end(); ++i) { - args.push_back(i->c_str()); + 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); @@ -309,7 +301,7 @@ public: { this->InitializeParser(); } - ~LogParser() CM_OVERRIDE { this->CleanupParser(); } + ~LogParser() override { this->CleanupParser(); } private: cmCTestSVN* SVN; cmCTestSVN::SVNInfo& SVNRepo; @@ -321,14 +313,14 @@ private: Change CurChange; std::vector 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") { @@ -346,12 +338,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); } - 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 +362,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 +372,7 @@ bool cmCTestSVN::LoadRevisions() { bool result = true; // Get revisions for all the external repositories - std::vector::iterator itbeg = this->Repositories.begin(); - std::vector::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 +410,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 +430,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 +496,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)); diff --git a/Source/CTest/cmCTestSVN.h b/Source/CTest/cmCTestSVN.h index 46b077835..dbc7fdef6 100644 --- a/Source/CTest/cmCTestSVN.h +++ b/Source/CTest/cmCTestSVN.h @@ -3,7 +3,7 @@ #ifndef cmCTestSVN_h #define cmCTestSVN_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestGlobalVC.h" @@ -24,14 +24,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 const& parameters, OutputParser* out, OutputParser* err); @@ -77,8 +77,8 @@ private: 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 const& changes); @@ -86,7 +86,7 @@ private: void DoRevisionSVN(Revision const& revision, std::vector 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..fdd9622af 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -52,9 +52,9 @@ class cmCTestScriptFunctionBlocker : public cmFunctionBlocker { public: cmCTestScriptFunctionBlocker() {} - ~cmCTestScriptFunctionBlocker() CM_OVERRIDE {} + ~cmCTestScriptFunctionBlocker() 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,9 +75,9 @@ 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->CMake = nullptr; + this->GlobalGenerator = nullptr; this->ScriptStartTime = 0; @@ -93,18 +93,18 @@ 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; @@ -114,10 +114,10 @@ void cmCTestScriptHandler::Initialize() this->ScriptStartTime = 0; delete this->Makefile; - this->Makefile = CM_NULLPTR; + this->Makefile = nullptr; delete this->GlobalGenerator; - this->GlobalGenerator = CM_NULLPTR; + this->GlobalGenerator = nullptr; delete this->CMake; } @@ -193,7 +193,7 @@ 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(); @@ -219,7 +219,7 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg) } // 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; @@ -245,10 +245,9 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg) std::ostringstream message; message << "Error running command: ["; message << result << "] "; - for (std::vector::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] @@ -377,9 +376,8 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) // Add definitions of variables passed in on the command line: const std::map& defs = this->CTest->GetDefinitions(); - for (std::map::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 @@ -394,7 +392,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 @@ -595,7 +593,7 @@ int cmCTestScriptHandler::CheckOutSourceDir() if (!cmSystemTools::FileExists(this->SourceDir.c_str()) && !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( @@ -654,15 +652,14 @@ int cmCTestScriptHandler::PerformExtraUpdates() // do an initial cvs update as required command = this->UpdateCmd; - std::vector::iterator it; - for (it = this->ExtraUpdates.begin(); it != this->ExtraUpdates.end(); ++it) { + for (std::string const& eu : this->ExtraUpdates) { std::vector 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); @@ -670,7 +667,7 @@ int cmCTestScriptHandler::PerformExtraUpdates() fullCommand.c_str(), &output, &output, &retVal, cvsArgs[0].c_str(), this->HandlerVerbose, 0 /*this->TimeOut*/); if (!res || retVal != 0) { - cmSystemTools::Error("Unable to perform extra updates:\n", it->c_str(), + cmSystemTools::Error("Unable to perform extra updates:\n", eu.c_str(), "\nWith output:\n", output.c_str()); return 0; } @@ -765,7 +762,7 @@ int cmCTestScriptHandler::RunConfigurationDashboard() command = this->CMakeCmd; command += " \""; command += this->SourceDir; - output = ""; + output.clear(); command += "\""; retVal = 0; cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, @@ -803,9 +800,9 @@ int cmCTestScriptHandler::RunConfigurationDashboard() std::vector 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); @@ -852,7 +849,7 @@ bool cmCTestScriptHandler::WriteInitialCache(const char* directory, return false; } - if (text != CM_NULLPTR) { + if (text != nullptr) { fout.write(text, strlen(text)); } diff --git a/Source/CTest/cmCTestScriptHandler.h b/Source/CTest/cmCTestScriptHandler.h index 667870260..b6cd97b73 100644 --- a/Source/CTest/cmCTestScriptHandler.h +++ b/Source/CTest/cmCTestScriptHandler.h @@ -3,7 +3,7 @@ #ifndef cmCTestScriptHandler_h #define cmCTestScriptHandler_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestGenericHandler.h" @@ -65,7 +65,7 @@ public: /** * Run a dashboard using a specified confiuration script */ - int ProcessHandler() CM_OVERRIDE; + int ProcessHandler() override; /* * Run a script @@ -98,9 +98,9 @@ public: double GetRemainingTimeAllowed(); cmCTestScriptHandler(); - ~cmCTestScriptHandler() CM_OVERRIDE; + ~cmCTestScriptHandler() override; - void Initialize() CM_OVERRIDE; + void Initialize() override; void CreateCMake(); cmake* GetCMake() { return this->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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/CTest/cmCTestStartCommand.cxx b/Source/CTest/cmCTestStartCommand.cxx index 01a874b45..4f0d87b1b 100644 --- a/Source/CTest/cmCTestStartCommand.cxx +++ b/Source/CTest/cmCTestStartCommand.cxx @@ -29,12 +29,12 @@ bool cmCTestStartCommand::InitialPass(std::vector 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* src_dir = nullptr; + const char* bld_dir = nullptr; cnt++; - this->CTest->SetSpecificTrack(CM_NULLPTR); + this->CTest->SetSpecificTrack(nullptr); if (cnt < args.size() - 1) { if (args[cnt] == "TRACK") { cnt++; 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 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..1794ca64b 100644 --- a/Source/CTest/cmCTestSubmitCommand.cxx +++ b/Source/CTest/cmCTestSubmitCommand.cxx @@ -86,7 +86,7 @@ cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler() extraFiles.end()); if (!this->CTest->SubmitExtraFiles(newExtraFiles)) { this->SetError("problem submitting extra files."); - return CM_NULLPTR; + return nullptr; } } @@ -94,7 +94,7 @@ cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler() this->CTest->GetInitializedHandler("submit"); if (!handler) { this->SetError("internal CTest error. Cannot instantiate submit handler"); - return CM_NULLPTR; + return nullptr; } // If no FILES or PARTS given, *all* PARTS are submitted by default. diff --git a/Source/CTest/cmCTestSubmitCommand.h b/Source/CTest/cmCTestSubmitCommand.h index cf65cdc8d..c4b84ce9f 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" @@ -38,7 +38,7 @@ public: /** * This is a virtual constructor for the command. */ - cmCommand* Clone() CM_OVERRIDE + cmCommand* Clone() override { cmCTestSubmitCommand* ni = new cmCTestSubmitCommand; ni->CTest = this->CTest; @@ -47,20 +47,20 @@ public: } bool InitialPass(std::vector 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 { diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 8d62fa156..e51e16843 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -13,6 +13,7 @@ #include "cmCTest.h" #include "cmCTestCurl.h" #include "cmCTestScriptHandler.h" +#include "cmCryptoHash.h" #include "cmCurl.h" #include "cmGeneratedFileStream.h" #include "cmProcessOutput.h" @@ -37,7 +38,7 @@ class cmCTestSubmitHandler::ResponseParser : public cmXMLParser { public: ResponseParser() { this->Status = STATUS_OK; } - ~ResponseParser() CM_OVERRIDE {} + ~ResponseParser() override {} public: enum StatusType @@ -65,17 +66,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); } - 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()); @@ -99,7 +100,7 @@ private: static size_t cmCTestSubmitHandlerWriteMemoryCallback(void* ptr, size_t size, size_t nmemb, void* data) { - int realsize = (int)(size * nmemb); + int realsize = static_cast(size * nmemb); cmCTestSubmitHandlerVectorOfChar* vec = static_cast(data); @@ -139,12 +140,12 @@ void cmCTestSubmitHandler::Initialize() this->HasWarnings = false; this->HasErrors = false; this->Superclass::Initialize(); - this->HTTPProxy = ""; + this->HTTPProxy.clear(); this->HTTPProxyType = 0; - this->HTTPProxyAuth = ""; - this->FTPProxy = ""; + this->HTTPProxyAuth.clear(); + this->FTPProxy.clear(); this->FTPProxyType = 0; - this->LogFile = CM_NULLPTR; + this->LogFile = nullptr; this->Files.clear(); } @@ -161,8 +162,7 @@ bool cmCTestSubmitHandler::SubmitUsingFTP(const std::string& localprefix, /* 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) { + for (std::string const& file : files) { /* get a curl handle */ curl = curl_easy_init(); if (curl) { @@ -191,12 +191,12 @@ bool cmCTestSubmitHandler::SubmitUsingFTP(const std::string& localprefix, ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); - std::string local_file = *file; + std::string local_file = file; if (!cmSystemTools::FileExists(local_file.c_str())) { - local_file = localprefix + "/" + *file; + local_file = localprefix + "/" + file; } std::string upload_as = - url + "/" + remoteprefix + cmSystemTools::GetFilenameName(*file); + url + "/" + remoteprefix + cmSystemTools::GetFilenameName(file); if (!cmSystemTools::FileExists(local_file.c_str())) { cmCTestLog(this->CTest, ERROR_MESSAGE, @@ -238,8 +238,8 @@ bool cmCTestSubmitHandler::SubmitUsingFTP(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); @@ -303,15 +303,14 @@ 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::const_iterator h = this->HttpHeaders.begin(); - h != this->HttpHeaders.end(); ++h) { + for (std::string const& h : this->HttpHeaders) { cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Add HTTP Header: \"" << *h << "\"" << std::endl, + " 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 */ @@ -322,18 +321,15 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix, cmSystemTools::ExpandListArgument(curlopt, args); bool verifyPeerOff = false; bool verifyHostOff = false; - for (std::vector::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,19 +384,18 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix, ::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); - std::string local_file = *file; + std::string local_file = file; if (!cmSystemTools::FileExists(local_file.c_str())) { - local_file = localprefix + "/" + *file; + local_file = localprefix + "/" + file; } 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]; + for (char c : remote_file) { char hexCh[4] = { 0, 0, 0, 0 }; hexCh[0] = c; switch (c) { @@ -412,7 +407,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix, case ' ': case '=': case '%': - sprintf(hexCh, "%%%02X", (int)c); + sprintf(hexCh, "%%%02X", static_cast(c)); ofile.append(hexCh); break; default: @@ -428,10 +423,8 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix, 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())) { @@ -472,8 +465,8 @@ 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); @@ -496,18 +489,18 @@ 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 == "" + int delay = retryDelay.empty() ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay") .c_str()) : atoi(retryDelay.c_str()); - int count = retryCount == "" + int count = retryCount.empty() ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryCount") .c_str()) : atoi(retryCount.c_str()); @@ -630,8 +623,7 @@ bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::set& files, /* 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) { + for (std::string const& file : files) { /* get a curl handle */ curl = curl_easy_init(); if (curl) { @@ -668,14 +660,12 @@ bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::set& files, /* 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); - std::string rfile = remoteprefix + cmSystemTools::GetFilenameName(*file); + 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; + for (char c : rfile) { char hexCh[4] = { 0, 0, 0, 0 }; hexCh[0] = c; switch (c) { @@ -687,7 +677,7 @@ bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::set& files, case ' ': case '=': case '%': - sprintf(hexCh, "%%%02X", (int)c); + sprintf(hexCh, "%%%02X", static_cast(c)); ofile.append(hexCh); break; default: @@ -765,7 +755,7 @@ bool cmCTestSubmitHandler::SubmitUsingSCP(const std::string& scp_command, 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); + argv.push_back(nullptr); cmsysProcess* cp = cmsysProcess_New(); cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); @@ -773,16 +763,15 @@ bool cmCTestSubmitHandler::SubmitUsingSCP(const std::string& scp_command, int problems = 0; - cmCTest::SetOfStrings::const_iterator file; - for (file = files.begin(); file != files.end(); ++file) { + for (std::string const& file : files) { int retVal; std::string lfname = localprefix; cmSystemTools::ConvertToUnixSlashes(lfname); - lfname += "/" + *file; + lfname += "/" + file; lfname = cmSystemTools::ConvertToOutputPath(lfname.c_str()); argv[1] = lfname.c_str(); - std::string rfname = url + "/" + remoteprefix + *file; + std::string rfname = url + "/" + remoteprefix + file; argv[2] = rfname.c_str(); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \"" << argv[2] @@ -798,7 +787,7 @@ bool cmCTestSubmitHandler::SubmitUsingSCP(const std::string& scp_command, cmProcessOutput processOutput; std::string strdata; - while (cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) { + while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) { processOutput.DecodeText(data, length, strdata); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(strdata.c_str(), strdata.size()), @@ -811,7 +800,7 @@ bool cmCTestSubmitHandler::SubmitUsingSCP(const std::string& scp_command, this->Quiet); } - cmsysProcess_WaitForExit(cp, CM_NULLPTR); + cmsysProcess_WaitForExit(cp, nullptr); int result = cmsysProcess_GetState(cp); @@ -865,12 +854,11 @@ bool cmCTestSubmitHandler::SubmitUsingCP(const std::string& localprefix, return false; } - cmCTest::SetOfStrings::const_iterator file; - for (file = files.begin(); file != files.end(); ++file) { + for (std::string const& file : files) { std::string lfname = localprefix; cmSystemTools::ConvertToUnixSlashes(lfname); - lfname += "/" + *file; - std::string rfname = destination + "/" + remoteprefix + *file; + 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, @@ -903,13 +891,12 @@ bool cmCTestSubmitHandler::SubmitUsingXMLRPC( 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) { + for (std::string const& file : files) { xmlrpc_value* result; - std::string local_file = *file; + std::string local_file = file; if (!cmSystemTools::FileExists(local_file.c_str())) { - local_file = localprefix + "/" + *file; + local_file = localprefix + "/" + file; } cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Submit file: " << local_file << std::endl, @@ -949,8 +936,9 @@ bool cmCTestSubmitHandler::SubmitUsingXMLRPC( char remoteCommand[] = "Submit.put"; char* pRealURL = const_cast(realURL.c_str()); - result = xmlrpc_client_call(&env, pRealURL, remoteCommand, "(6)", - fileBuffer, (xmlrpc_int32)fileSize); + result = + xmlrpc_client_call(&env, pRealURL, remoteCommand, "(6)", fileBuffer, + static_cast(fileSize)); delete[] fileBuffer; @@ -1037,30 +1025,29 @@ 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 (!retryDelayString.empty()) { if (!cmSystemTools::StringToULong(retryDelayString.c_str(), &retryDelay)) { cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : " << retryDelayString << std::endl); } } 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); } } - 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 @@ -1084,8 +1071,8 @@ 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=" << static_cast(cmSystemTools::GetTime()) << "&" + << "endtime=" << static_cast(cmSystemTools::GetTime()) << "&" << "datafilesmd5[0]=" << md5sum << "&" << "type=" << curl.Escape(typeString); std::string fields = str.str(); @@ -1324,13 +1311,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); @@ -1357,9 +1342,8 @@ int cmCTestSubmitHandler::ProcessHandler() 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++; } } @@ -1377,7 +1361,7 @@ int cmCTestSubmitHandler::ProcessHandler() std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod")); - if (dropMethod == "" || dropMethod == "ftp") { + if (dropMethod.empty() || dropMethod == "ftp") { ofs << "Using drop method: FTP" << std::endl; cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Using FTP submit method" << std::endl diff --git a/Source/CTest/cmCTestSubmitHandler.h b/Source/CTest/cmCTestSubmitHandler.h index 2923f4f3d..b4d0e7772 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,14 +25,14 @@ 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 const& parts); diff --git a/Source/CTest/cmCTestTestCommand.cxx b/Source/CTest/cmCTestTestCommand.cxx index 075b1403a..febd39e76 100644 --- a/Source/CTest/cmCTestTestCommand.cxx +++ b/Source/CTest/cmCTestTestCommand.cxx @@ -27,7 +27,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; } @@ -124,6 +124,12 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler() } 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; } 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..c7ed92725 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1,15 +1,14 @@ /* 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 +#include +#include +#include #include #include #include +#include // IWYU pragma: keep #include #include #include @@ -30,9 +29,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 +41,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 +53,7 @@ public: * the CMakeLists.txt file. */ bool InitialPass(std::vector const& args, - cmExecutionStatus& /*unused*/) CM_OVERRIDE; + cmExecutionStatus& /*unused*/) override; cmCTestTestHandler* TestHandler; }; @@ -66,17 +65,16 @@ bool cmCTestSubdirCommand::InitialPass(std::vector const& args, this->SetError("called with incorrect number of arguments"); return false; } - std::vector::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.c_str())) { + fname = arg; } else { fname = cwd; fname += "/"; - fname += *it; + fname += arg; } if (!cmSystemTools::FileIsDirectory(fname)) { @@ -117,7 +115,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 +127,7 @@ public: * the CMakeLists.txt file. */ bool InitialPass(std::vector const& args, - cmExecutionStatus& /*unused*/) CM_OVERRIDE; + cmExecutionStatus& /*unused*/) override; cmCTestTestHandler* TestHandler; }; @@ -182,7 +180,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 +192,7 @@ public: * the CMakeLists.txt file. */ bool InitialPass(std::vector const& /*args*/, - cmExecutionStatus& /*unused*/) CM_OVERRIDE; + cmExecutionStatus& /*unused*/) override; cmCTestTestHandler* TestHandler; }; @@ -215,7 +213,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 +225,7 @@ public: * the CMakeLists.txt file. */ bool InitialPass(std::vector const& /*args*/, - cmExecutionStatus& /*unused*/) CM_OVERRIDE; + cmExecutionStatus& /*unused*/) override; cmCTestTestHandler* TestHandler; }; @@ -238,6 +236,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 const& /*unused*/, + cmExecutionStatus& /*unused*/) override; + + cmCTestTestHandler* TestHandler; +}; + +bool cmCTestSetDirectoryPropertiesCommand::InitialPass( + std::vector 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 +333,7 @@ cmCTestTestHandler::cmCTestTestHandler() this->MemCheck = false; - this->LogFile = CM_NULLPTR; + this->LogFile = nullptr; // regex to detect ... this->DartStuff.compile("()"); @@ -323,8 +351,8 @@ void cmCTestTestHandler::Initialize() this->TestResults.clear(); this->CustomTestsIgnore.clear(); - this->StartTest = ""; - this->EndTest = ""; + this->StartTest.clear(); + this->EndTest.clear(); this->CustomPreTest.clear(); this->CustomPostTest.clear(); @@ -340,13 +368,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(); } @@ -476,10 +504,9 @@ int cmCTestTestHandler::ProcessHandler() cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl << "The following tests passed:" << std::endl, this->Quiet); - for (std::vector::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 +516,10 @@ int cmCTestTestHandler::ProcessHandler() SetOfTests resultsSet(this->TestResults.begin(), this->TestResults.end()); std::vector 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); } } @@ -506,11 +532,15 @@ int cmCTestTestHandler::ProcessHandler() << static_cast(percent + .5f) << "% tests passed, " << failed.size() << " tests failed 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)); + sprintf(realBuf, "%6.2f sec", clock_finish - clock_start); cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\nTotal Test time (real) = " << realBuf << "\n", this->Quiet); @@ -522,17 +552,15 @@ int cmCTestTestHandler::ProcessHandler() this->StartLogFile("TestsDisabled", ofs); const char* disabled_reason; - for (std::vector::iterator dtit = - disabledTests.begin(); - dtit != disabledTests.end(); ++dtit) { - ofs << dtit->TestCount << ":" << dtit->Name << std::endl; - if (dtit->CompletionStatus == "Disabled") { + 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 + << std::setw(3) << dt.TestCount << " - " << dt.Name << " (" << disabled_reason << ")" << std::endl); } } @@ -543,16 +571,14 @@ int cmCTestTestHandler::ProcessHandler() << "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; - cmCTestLog( - this->CTest, HANDLER_OUTPUT, "\t" - << std::setw(3) << ftit->TestCount << " - " << ftit->Name << " (" - << this->GetTestStatus(ftit->Status) << ")" << 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; + cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t" + << std::setw(3) << ft.TestCount << " - " << ft.Name + << " (" << this->GetTestStatus(ft) << ")" << std::endl); } } } @@ -566,7 +592,7 @@ int cmCTestTestHandler::ProcessHandler() 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 +600,98 @@ 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 subprojects = + this->CTest->GetLabelsForSubprojects(); std::map labelTimes; std::map labelCounts; std::set 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::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::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::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 * result.Properties->Processors; + ++labelCounts[l]; } } } + // if no labels are found return and print nothing + if (labels.empty()) { + return; + } // now print times - if (!labels.empty()) { + 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::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" << 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 +709,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::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 +734,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::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 +764,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(tmsize)); } else { this->ExpandTestsToRunInformation(inREcnt); } @@ -748,9 +781,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 +792,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 +800,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 +822,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 +834,8 @@ void cmCTestTestHandler::ComputeTestListForRerunFailed() continue; } - it->Index = cnt; - finalList.push_back(*it); + tp.Index = cnt; + finalList.push_back(tp); } UpdateForFixtures(finalList); @@ -857,24 +889,18 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const it != this->TestList.end(); ++it) { const cmCTestTestProperties& p = *it; - const std::set& setups = p.FixturesSetup; - for (std::set::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& cleanups = p.FixturesCleanup; - for (std::set::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 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 +908,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 > fixtureRequirements; - std::map > setupFixturesAdded; + std::map> fixtureRequirements; + std::map> setupFixturesAdded; // Use integer index for iteration because we append to // the tests vector as we go @@ -908,10 +934,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 fixtures = tests[i].FixturesRequired; - for (std::set::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 +1033,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const } // 2. Record all setup fixtures included in the final list of tests - for (std::set::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 +1047,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& cleanups = p.FixturesCleanup; - for (std::set::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 >::const_iterator cIt = + std::map>::const_iterator cIt = fixtureRequirements.find(fixture); if (cIt != fixtureRequirements.end()) { const std::vector& indices = cIt->second; - for (std::vector::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 +1071,8 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const cIt = setupFixturesAdded.find(fixture); if (cIt != setupFixturesAdded.end()) { const std::vector& indices = cIt->second; - for (std::vector::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); @@ -1078,9 +1091,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const 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(); } @@ -1215,12 +1226,10 @@ void cmCTestTestHandler::ProcessDirectory(std::vector& passed, bool randomSchedule = this->CTest->GetScheduleType() == "Random"; if (randomSchedule) { - srand((unsigned)time(CM_NULLPTR)); + srand(static_cast(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) { @@ -1232,19 +1241,17 @@ void cmCTestTestHandler::ProcessDirectory(std::vector& passed, } if (!p.Depends.empty()) { - for (std::vector::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); @@ -1277,83 +1284,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); 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::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 @@ -1371,32 +1380,31 @@ void cmCTestTestHandler::GenerateDartOutput(cmXMLWriter& 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 const& labels = result->Properties->Labels; - for (std::vector::const_iterator li = labels.begin(); - li != labels.end(); ++li) { - xml.Element("Label", *li); + std::vector const& labels = result.Properties->Labels; + for (std::string const& label : labels) { + xml.Element("Label", label); } xml.EndElement(); // Labels } @@ -1405,20 +1413,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::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 +1438,16 @@ void cmCTestTestHandler::AttachFiles(cmXMLWriter& xml, int cmCTestTestHandler::ExecuteCommands(std::vector& vec) { - std::vector::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.c_str(), 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; } } @@ -1554,11 +1558,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); } @@ -1593,9 +1595,9 @@ 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; } } @@ -1603,9 +1605,8 @@ std::string cmCTestTestHandler::FindExecutable( cmCTestLog(ctest, HANDLER_OUTPUT, "Could not find executable " << testCommand << "\n" << "Looked in the following places:\n"); - for (std::vector::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"); } } @@ -1635,9 +1636,9 @@ void cmCTestTestHandler::GetListOfTests() cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR 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 +1661,12 @@ void cmCTestTestHandler::GetListOfTests() newCom4->TestHandler = this; cm.GetState()->AddBuiltinCommand("set_tests_properties", newCom4); + // Add handler for 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 +1678,7 @@ void cmCTestTestHandler::GetListOfTests() return; } - if (!mf->ReadListFile(testFilename)) { + if (!mf.ReadListFile(testFilename)) { return; } if (cmSystemTools::GetErrorOccuredFlag()) { @@ -1693,17 +1700,20 @@ void cmCTestTestHandler::UseExcludeRegExp() this->UseExcludeRegExpFirst = !this->UseIncludeRegExpFlag; } -const char* cmCTestTestHandler::GetTestStatus(int status) +const char* 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.c_str(); + } return statuses[status]; } @@ -1792,7 +1802,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 @@ -2086,116 +2096,117 @@ bool cmCTestTestHandler::SetTestsProperties( break; } std::string val = *it; - std::vector::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 == "WILL_FAIL") { - rtit->WillFail = cmSystemTools::IsOn(val.c_str()); + rt.WillFail = cmSystemTools::IsOn(val.c_str()); } if (key == "DISABLED") { - rtit->Disabled = cmSystemTools::IsOn(val.c_str()); + rt.Disabled = cmSystemTools::IsOn(val.c_str()); } 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 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 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 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 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 = atof(val.c_str()); + rt.ExplicitTimeout = true; } if (key == "COST") { - rtit->Cost = static_cast(atof(val.c_str())); + rt.Cost = static_cast(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.c_str()); } if (key == "FAIL_REGULAR_EXPRESSION") { std::vector lval; cmSystemTools::ExpandListArgument(val, lval); - std::vector::iterator crit; - for (crit = lval.begin(); crit != lval.end(); ++crit) { - rtit->ErrorRegularExpressions.push_back( + for (std::string const& cr : lval) { + rt.ErrorRegularExpressions.push_back( std::pair( - cmsys::RegularExpression(crit->c_str()), - std::string(*crit))); + cmsys::RegularExpression(cr.c_str()), std::string(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 == "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 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::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; + rt.Measurements[mKey] = mVal; } else { - rtit->Measurements[val] = "1"; + rt.Measurements[val] = "1"; } } if (key == "PASS_REGULAR_EXPRESSION") { std::vector lval; cmSystemTools::ExpandListArgument(val, lval); - std::vector::iterator crit; - for (crit = lval.begin(); crit != lval.end(); ++crit) { - rtit->RequiredRegularExpressions.push_back( + for (std::string const& cr : lval) { + rt.RequiredRegularExpressions.push_back( std::pair( - cmsys::RegularExpression(crit->c_str()), - std::string(*crit))); + cmsys::RegularExpression(cr.c_str()), std::string(cr))); } } if (key == "WORKING_DIRECTORY") { - rtit->Directory = val; + rt.Directory = val; } if (key == "TIMEOUT_AFTER_MATCH") { std::vector propArgs; @@ -2205,15 +2216,13 @@ bool cmCTestTestHandler::SetTestsProperties( "TIMEOUT_AFTER_MATCH expects two arguments, found " << propArgs.size() << std::endl); } else { - rtit->AlternateTimeout = atof(propArgs[0].c_str()); + rt.AlternateTimeout = atof(propArgs[0].c_str()); std::vector lval; cmSystemTools::ExpandListArgument(propArgs[1], lval); - std::vector::iterator crit; - for (crit = lval.begin(); crit != lval.end(); ++crit) { - rtit->TimeoutRegularExpressions.push_back( + for (std::string const& cr : lval) { + rt.TimeoutRegularExpressions.push_back( std::pair( - cmsys::RegularExpression(crit->c_str()), - std::string(*crit))); + cmsys::RegularExpression(cr.c_str()), std::string(cr))); } } } @@ -2224,6 +2233,53 @@ bool cmCTestTestHandler::SetTestsProperties( return true; } +bool cmCTestTestHandler::SetDirectoryProperties( + const std::vector& args) +{ + std::vector::const_iterator it; + std::vector 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 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::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& args) { const std::string& testname = args[0]; diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 0edcb143a..394d20ed0 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -3,7 +3,7 @@ #ifndef cmCTestTestHandler_h #define cmCTestTestHandler_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCTestGenericHandler.h" @@ -36,7 +36,7 @@ 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 @@ -54,7 +54,7 @@ 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 /// them on @@ -90,7 +90,12 @@ public: */ bool SetTestsProperties(const std::vector& args); - void Initialize() CM_OVERRIDE; + /** + * Set directory properties + */ + bool SetDirectoryProperties(const std::vector& args); + + void Initialize() override; // NOTE: This struct is Saved/Restored // in cmCTestTestHandler, if you add to this class @@ -105,11 +110,11 @@ public: std::vector Depends; std::vector AttachedFiles; std::vector AttachOnFail; - std::vector > + std::vector> ErrorRegularExpressions; - std::vector > + std::vector> RequiredRegularExpressions; - std::vector > + std::vector> TimeoutRegularExpressions; std::map Measurements; bool IsInBasedOnREOptions; @@ -144,6 +149,7 @@ public: double ExecutionTime; int ReturnValue; int Status; + std::string ExceptionStatus; bool CompressOutput; std::string CompletionStatus; std::string Output; @@ -182,10 +188,12 @@ protected: virtual void GenerateTestCommand(std::vector& args, int test); int ExecuteCommands(std::vector& 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); @@ -226,7 +234,8 @@ private: */ virtual void GenerateDartOutput(cmXMLWriter& xml); - void PrintLabelSummary(); + void PrintLabelOrSubprojectSummary(bool isSubProject); + /** * Run the tests for a directory and any subdirectories */ @@ -262,7 +271,7 @@ private: */ std::string FindTheExecutable(const char* exe); - const char* GetTestStatus(int status); + const char* GetTestStatus(cmCTestTestResult const&); void ExpandTestsToRunInformation(size_t numPossibleTests); void ExpandTestsToRunInformationForRerunFailed(); diff --git a/Source/CTest/cmCTestUpdateCommand.cxx b/Source/CTest/cmCTestUpdateCommand.cxx index 8c037545f..3d800f8b3 100644 --- a/Source/CTest/cmCTestUpdateCommand.cxx +++ b/Source/CTest/cmCTestUpdateCommand.cxx @@ -78,12 +78,12 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler() this->CTest->GetInitializedHandler("update"); if (!handler) { this->SetError("internal CTest error. Cannot instantiate update handler"); - return CM_NULLPTR; + return nullptr; } 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..786ed5e47 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,7 @@ #include "cmVersion.h" #include "cmXMLWriter.h" -#include "cm_auto_ptr.hxx" +#include // IWYU pragma: keep #include static const char* cmCTestUpdateHandlerUpdateStrings[] = { @@ -39,7 +40,7 @@ cmCTestUpdateHandler::cmCTestUpdateHandler() void cmCTestUpdateHandler::Initialize() { this->Superclass::Initialize(); - this->UpdateCommand = ""; + this->UpdateCommand.clear(); this->UpdateType = e_CVS; } @@ -134,28 +135,28 @@ int cmCTestUpdateHandler::ProcessHandler() , this->Quiet); // Create an object to interact with the VCS tool. - CM_AUTO_PTR vc; + std::unique_ptr vc; switch (this->UpdateType) { case e_CVS: - vc.reset(new cmCTestCVS(this->CTest, ofs)); + vc = cm::make_unique(this->CTest, ofs); break; case e_SVN: - vc.reset(new cmCTestSVN(this->CTest, ofs)); + vc = cm::make_unique(this->CTest, ofs); break; case e_BZR: - vc.reset(new cmCTestBZR(this->CTest, ofs)); + vc = cm::make_unique(this->CTest, ofs); break; case e_GIT: - vc.reset(new cmCTestGIT(this->CTest, ofs)); + vc = cm::make_unique(this->CTest, ofs); break; case e_HG: - vc.reset(new cmCTestHG(this->CTest, ofs)); + vc = cm::make_unique(this->CTest, ofs); break; case e_P4: - vc.reset(new cmCTestP4(this->CTest, ofs)); + vc = cm::make_unique(this->CTest, ofs); break; default: - vc.reset(new cmCTestVC(this->CTest, ofs)); + vc = cm::make_unique(this->CTest, ofs); break; } vc->SetCommandLineTool(this->UpdateCommand); @@ -309,7 +310,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..d85f35f6f 100644 --- a/Source/CTest/cmCTestUploadCommand.cxx +++ b/Source/CTest/cmCTestUploadCommand.cxx @@ -18,7 +18,7 @@ cmCTestGenericHandler* cmCTestUploadCommand::InitializeHandler() this->CTest->GetInitializedHandler("upload"); if (!handler) { this->SetError("internal CTest error. Cannot instantiate upload handler"); - return CM_NULLPTR; + return nullptr; } static_cast(handler)->SetFiles(this->Files); diff --git a/Source/CTest/cmCTestUploadCommand.h b/Source/CTest/cmCTestUploadCommand.h index 6e721796a..61bf1cc58 100644 --- a/Source/CTest/cmCTestUploadCommand.h +++ b/Source/CTest/cmCTestUploadCommand.h @@ -3,7 +3,7 @@ #ifndef cmCTestUploadCommand_h #define cmCTestUploadCommand_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCTest.h" #include "cmCTestHandlerCommand.h" @@ -27,7 +27,7 @@ public: /** * 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 +38,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 { diff --git a/Source/CTest/cmCTestUploadHandler.cxx b/Source/CTest/cmCTestUploadHandler.cxx index 05a39840d..59a5de484 100644 --- a/Source/CTest/cmCTestUploadHandler.cxx +++ b/Source/CTest/cmCTestUploadHandler.cxx @@ -7,7 +7,6 @@ #include "cmXMLWriter.h" #include -#include #include cmCTestUploadHandler::cmCTestUploadHandler() @@ -37,7 +36,6 @@ int cmCTestUploadHandler::ProcessHandler() } std::string buildname = cmCTest::SafeBuildIdField(this->CTest->GetCTestConfiguration("BuildName")); - cmCTest::SetOfStrings::const_iterator it; cmXMLWriter xml(ofs); xml.StartDocument(); @@ -55,14 +53,14 @@ int cmCTestUploadHandler::ProcessHandler() 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..ff5057418 100644 --- a/Source/CTest/cmCTestUploadHandler.h +++ b/Source/CTest/cmCTestUploadHandler.h @@ -3,7 +3,7 @@ #ifndef cmCTestUploadHandler_h #define cmCTestUploadHandler_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCTest.h" #include "cmCTestGenericHandler.h" @@ -20,14 +20,14 @@ public: typedef cmCTestGenericHandler Superclass; cmCTestUploadHandler(); - ~cmCTestUploadHandler() CM_OVERRIDE {} + ~cmCTestUploadHandler() 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); diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx index fb2742e08..fd7f37ac8 100644 --- a/Source/CTest/cmCTestVC.cxx +++ b/Source/CTest/cmCTestVC.cxx @@ -56,11 +56,11 @@ bool cmCTestVC::InitialCheckout(const char* command) // Construct the initial checkout command line. std::vector args = cmSystemTools::ParseArguments(command); std::vector vc_co; - for (std::vector::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"; @@ -113,7 +113,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() diff --git a/Source/CTest/cmCTestVC.h b/Source/CTest/cmCTestVC.h index 6400bcda3..69a3bf023 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 #include @@ -100,8 +100,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 +117,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..308e6f7a3 100644 --- a/Source/CTest/cmParseBlanketJSCoverage.cxx +++ b/Source/CTest/cmParseBlanketJSCoverage.cxx @@ -112,17 +112,15 @@ cmParseBlanketJSCoverage::cmParseBlanketJSCoverage( bool cmParseBlanketJSCoverage::LoadCoverageData(std::vector 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..4cd6588be 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; } @@ -148,7 +146,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 +154,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..61ce7d48e 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 #include @@ -22,13 +21,13 @@ public: this->SkipThisClass = false; this->FilePaths.push_back(this->Coverage.SourceDir); this->FilePaths.push_back(this->Coverage.BinaryDir); - this->CurFileName = ""; + this->CurFileName.clear(); } - ~XMLParser() CM_OVERRIDE {} + ~XMLParser() 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 +38,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 +50,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,22 +67,22 @@ 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; + for (std::string const& filePath : FilePaths) { + finalpath = filePath + "/" + filename; if (cmSystemTools::FileExists(finalpath.c_str())) { this->CurFileName = finalpath; break; @@ -92,7 +91,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()); diff --git a/Source/CTest/cmParseDelphiCoverage.cxx b/Source/CTest/cmParseDelphiCoverage.cxx index 4b781a6db..6d82cb2e7 100644 --- a/Source/CTest/cmParseDelphiCoverage.cxx +++ b/Source/CTest/cmParseDelphiCoverage.cxx @@ -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); diff --git a/Source/CTest/cmParseGTMCoverage.cxx b/Source/CTest/cmParseGTMCoverage.cxx index e4ee699c4..9948eded2 100644 --- a/Source/CTest/cmParseGTMCoverage.cxx +++ b/Source/CTest/cmParseGTMCoverage.cxx @@ -182,7 +182,7 @@ 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; @@ -233,8 +233,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..7acb5ca3f 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,25 +18,25 @@ public: : CTest(ctest) , Coverage(cont) { - this->FilePath = ""; - this->PackagePath = ""; - this->PackageName = ""; + this->FilePath.clear(); + this->PackagePath.clear(); + this->PackageName.clear(); } - ~XMLParser() CM_OVERRIDE {} + ~XMLParser() 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") { 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); @@ -121,9 +119,8 @@ protected: } // Check if any of the locations found match our package. - for (std::vector::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..1419743fc 100644 --- a/Source/CTest/cmParseMumpsCoverage.cxx +++ b/Source/CTest/cmParseMumpsCoverage.cxx @@ -4,13 +4,11 @@ #include "cmCTestCoverageHandler.h" #include "cmSystemTools.h" -#include "cmConfigure.h" #include "cmsys/FStream.hxx" #include "cmsys/Glob.hxx" #include #include #include -#include cmParseMumpsCoverage::cmParseMumpsCoverage( cmCTestCoverageHandlerContainer& cont, cmCTest* ctest) @@ -113,14 +111,12 @@ bool cmParseMumpsCoverage::LoadPackages(const char* d) std::string pat = d; pat += "/*.m"; glob.FindFiles(pat); - std::vector& files = glob.GetFiles(); - std::vector::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; + for (std::string& file : glob.GetFiles()) { + std::string name = cmSystemTools::GetFilenameName(file); + this->RoutineToDirectory[name.substr(0, name.size() - 2)] = file; // initialze 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 +131,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/cmProcess.cxx b/Source/CTest/cmProcess.cxx index f4ec6da29..f3c191b8a 100644 --- a/Source/CTest/cmProcess.cxx +++ b/Source/CTest/cmProcess.cxx @@ -2,14 +2,13 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmProcess.h" -#include "cmConfigure.h" #include "cmProcessOutput.h" #include "cmSystemTools.h" #include cmProcess::cmProcess() { - this->Process = CM_NULLPTR; + this->Process = nullptr; this->Timeout = 0; this->TotalTime = 0; this->ExitValue = 0; @@ -41,11 +40,10 @@ bool cmProcess::StartProcess() // put the command as arg0 this->ProcessArgs.push_back(this->Command.c_str()); // now put the command arguments in - for (std::vector::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(CM_NULLPTR); // null terminate the list + this->ProcessArgs.push_back(nullptr); // null terminate the list this->Process = cmsysProcess_New(); cmsysProcess_SetCommand(this->Process, &*this->ProcessArgs.begin()); if (!this->WorkingDirectory.empty()) { @@ -240,3 +238,8 @@ int cmProcess::GetExitException() { return cmsysProcess_GetExitException(this->Process); } + +std::string cmProcess::GetExitExceptionString() +{ + return cmsysProcess_GetExceptionString(this->Process); +} diff --git a/Source/CTest/cmProcess.h b/Source/CTest/cmProcess.h index 86e905aca..dfb02fe0d 100644 --- a/Source/CTest/cmProcess.h +++ b/Source/CTest/cmProcess.h @@ -38,6 +38,7 @@ public: int GetExitValue() { return this->ExitValue; } double GetTotalTime() { return this->TotalTime; } int GetExitException(); + std::string GetExitExceptionString(); /** * Read one line of output but block for no more than timeout. * Returns: diff --git a/Source/Checks/cm_cxx_attribute_fallthrough.cxx b/Source/Checks/cm_cxx_attribute_fallthrough.cxx index df43625a4..50605b70a 100644 --- a/Source/Checks/cm_cxx_attribute_fallthrough.cxx +++ b/Source/Checks/cm_cxx_attribute_fallthrough.cxx @@ -1,4 +1,4 @@ -int main(int argc, char* argv[]) +int main(int argc, char* []) { int i = 3; switch (argc) { diff --git a/Source/Checks/cm_cxx_auto_ptr.cxx b/Source/Checks/cm_cxx_auto_ptr.cxx deleted file mode 100644 index d3100fdc8..000000000 --- a/Source/Checks/cm_cxx_auto_ptr.cxx +++ /dev/null @@ -1,18 +0,0 @@ -#include - -std::auto_ptr get_auto_ptr() -{ - std::auto_ptr ptr; - ptr = std::auto_ptr(new int(0)); - return ptr; -} - -int use_auto_ptr(std::auto_ptr ptr) -{ - return *ptr; -} - -int main() -{ - return use_auto_ptr(get_auto_ptr()); -} diff --git a/Source/Checks/cm_cxx_eq_delete.cxx b/Source/Checks/cm_cxx_eq_delete.cxx deleted file mode 100644 index 809e4cfcf..000000000 --- a/Source/Checks/cm_cxx_eq_delete.cxx +++ /dev/null @@ -1,14 +0,0 @@ -struct Foo -{ - Foo() {} - ~Foo() {} - Foo(Foo const&) = delete; - Foo& operator=(Foo const&) = delete; - int test() const { return 0; } -}; - -int main() -{ - Foo const foo; - return foo.test(); -} diff --git a/Source/Checks/cm_cxx_fallthrough.cxx b/Source/Checks/cm_cxx_fallthrough.cxx index 7b35a5f29..2825bed1e 100644 --- a/Source/Checks/cm_cxx_fallthrough.cxx +++ b/Source/Checks/cm_cxx_fallthrough.cxx @@ -1,4 +1,4 @@ -int main(int argc, char* argv[]) +int main(int argc, char* []) { int i = 3; switch (argc) { diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake index 3b0802579..a30a5e690 100644 --- a/Source/Checks/cm_cxx_features.cmake +++ b/Source/Checks/cm_cxx_features.cmake @@ -14,8 +14,11 @@ 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}") # If using the feature causes warnings, treat it as broken/unavailable. if(check_output MATCHES "[Ww]arning") set(CMake_HAVE_CXX_${FEATURE} OFF CACHE INTERNAL "TRY_COMPILE" FORCE) @@ -38,8 +41,6 @@ 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) @@ -51,8 +52,4 @@ 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/Checks/cm_cxx_gnu_fallthrough.cxx b/Source/Checks/cm_cxx_gnu_fallthrough.cxx index 602109405..ebc15f431 100644 --- a/Source/Checks/cm_cxx_gnu_fallthrough.cxx +++ b/Source/Checks/cm_cxx_gnu_fallthrough.cxx @@ -1,4 +1,4 @@ -int main(int argc, char* argv[]) +int main(int argc, char* []) { int i = 3; switch (argc) { diff --git a/Source/Checks/cm_cxx_nullptr.cxx b/Source/Checks/cm_cxx_nullptr.cxx deleted file mode 100644 index 500684aee..000000000 --- a/Source/Checks/cm_cxx_nullptr.cxx +++ /dev/null @@ -1,14 +0,0 @@ -int test(int) -{ - return -1; -} - -int test(int*) -{ - return 0; -} - -int main() -{ - return test(nullptr); -} diff --git a/Source/Checks/cm_cxx_override.cxx b/Source/Checks/cm_cxx_override.cxx deleted file mode 100644 index 5a33fbb78..000000000 --- a/Source/Checks/cm_cxx_override.cxx +++ /dev/null @@ -1,24 +0,0 @@ -struct Foo -{ - Foo() {} - virtual ~Foo() {} - virtual int test() const = 0; -}; - -struct Bar : Foo -{ - Bar() {} - ~Bar() override {} - int test() const override { return 0; } -}; - -int test(Foo const& foo) -{ - return foo.test(); -} - -int main() -{ - Bar const bar; - return test(bar); -} diff --git a/Source/Checks/cm_cxx_unordered_map.cxx b/Source/Checks/cm_cxx_unordered_map.cxx deleted file mode 100644 index be3de252b..000000000 --- a/Source/Checks/cm_cxx_unordered_map.cxx +++ /dev/null @@ -1,7 +0,0 @@ -#include -int main() -{ - std::unordered_map map; - map[0] = 0; - return 0; -} diff --git a/Source/Checks/cm_cxx_unordered_set.cxx b/Source/Checks/cm_cxx_unordered_set.cxx deleted file mode 100644 index de4bb7765..000000000 --- a/Source/Checks/cm_cxx_unordered_set.cxx +++ /dev/null @@ -1,7 +0,0 @@ -#include -int main() -{ - std::unordered_set set; - set.insert(0); - return 0; -} diff --git a/Source/CursesDialog/CMakeLists.txt b/Source/CursesDialog/CMakeLists.txt index c5ac1f1a6..6023c83eb 100644 --- a/Source/CursesDialog/CMakeLists.txt +++ b/Source/CursesDialog/CMakeLists.txt @@ -17,10 +17,6 @@ set( CURSES_SRCS CursesDialog/ccmake ) -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..97d5579c2 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.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 "cmCursesForm.h" #include "cmCursesMainForm.h" @@ -18,30 +17,29 @@ #include 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 \n" - " ccmake " }, - { CM_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, " ccmake \n" + " ccmake " }, + { 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." }, + { 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 } }; + { nullptr, nullptr } }; -cmCursesForm* cmCursesForm::CurrentForm = CM_NULLPTR; +cmCursesForm* cmCursesForm::CurrentForm = nullptr; extern "C" { @@ -169,7 +167,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..cdb9478e1 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" @@ -21,7 +21,7 @@ public: // 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..e7ed09717 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 options; cmSystemTools::ExpandListArgument(stringsProp, options); - for (std::vector::iterator si = options.begin(); - si != options.end(); ++si) { - ow->AddOption(*si); + for (auto const& opt : options) { + ow->AddOption(opt); } ow->SetOption(value); } else { @@ -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..54b2f1fd1 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 diff --git a/Source/CursesDialog/cmCursesDummyWidget.h b/Source/CursesDialog/cmCursesDummyWidget.h index d9bb6babc..c509ae773 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" @@ -21,7 +21,7 @@ public: // 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..0a304023e 100644 --- a/Source/CursesDialog/cmCursesFilePathWidget.h +++ b/Source/CursesDialog/cmCursesFilePathWidget.h @@ -3,7 +3,7 @@ #ifndef cmCursesFilePathWidget_h #define cmCursesFilePathWidget_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCursesPathWidget.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..249b34936 100644 --- a/Source/CursesDialog/cmCursesForm.h +++ b/Source/CursesDialog/cmCursesForm.h @@ -3,7 +3,7 @@ #ifndef cmCursesForm_h #define cmCursesForm_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCursesStandardIncludes.h" diff --git a/Source/CursesDialog/cmCursesLabelWidget.h b/Source/CursesDialog/cmCursesLabelWidget.h index 267de7c8c..aab559b16 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" @@ -19,13 +19,13 @@ class cmCursesLabelWidget : public cmCursesWidget public: cmCursesLabelWidget(int width, int height, int left, int top, const std::string& name); - ~cmCursesLabelWidget() CM_OVERRIDE; + ~cmCursesLabelWidget() override; // 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..9bd1c11b5 100644 --- a/Source/CursesDialog/cmCursesLongMessageForm.cxx +++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx @@ -26,8 +26,8 @@ cmCursesLongMessageForm::cmCursesLongMessageForm( 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() @@ -105,7 +105,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 +114,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..2bcc15a20 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" @@ -18,16 +18,16 @@ class cmCursesLongMessageForm : public cmCursesForm public: cmCursesLongMessageForm(std::vector const& messages, const char* title); - ~cmCursesLongMessageForm() CM_OVERRIDE; + ~cmCursesLongMessageForm() override; // 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 +37,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..dbd024da6 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -17,6 +17,7 @@ #include "cmVersion.h" #include "cmake.h" +#include #include #include @@ -31,8 +32,8 @@ cmCursesMainForm::cmCursesMainForm(std::vector const& 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; @@ -59,7 +60,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,7 +71,7 @@ cmCursesMainForm::~cmCursesMainForm() delete this->Entries; if (this->CMakeInstance) { delete this->CMakeInstance; - this->CMakeInstance = CM_NULLPTR; + this->CMakeInstance = nullptr; } } @@ -180,7 +181,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) { @@ -210,7 +211,7 @@ 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 @@ -239,7 +240,7 @@ void cmCursesMainForm::RePost() 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 +260,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 @@ -341,23 +342,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(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, @@ -380,7 +379,7 @@ void cmCursesMainForm::PrintKeys(int process /* = 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); @@ -425,7 +424,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( field_userptr(this->Fields[findex - 2])); @@ -456,41 +455,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(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 +488,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'; @@ -529,7 +512,7 @@ void cmCursesMainForm::UpdateProgress(const char* msg, float prog, void* vp) char tmp[1024]; const char* cmsg = tmp; if (prog >= 0) { - sprintf(tmp, "%s %i%%", msg, (int)(100 * prog)); + sprintf(tmp, "%s %i%%", msg, static_cast(100 * prog)); } else { cmsg = msg; } @@ -557,7 +540,7 @@ int cmCursesMainForm::Configure(int noconfigure) this->FillCacheManagerFromUI(); this->CMakeInstance->SaveCache( this->CMakeInstance->GetHomeOutputDirectory()); - this->LoadCache(CM_NULLPTR); + this->LoadCache(nullptr); // Get rid of previous errors this->Errors = std::vector(); @@ -574,7 +557,7 @@ int cmCursesMainForm::Configure(int noconfigure) } else { retVal = this->CMakeInstance->Configure(); } - this->CMakeInstance->SetProgressCallback(CM_NULLPTR, CM_NULLPTR); + this->CMakeInstance->SetProgressCallback(nullptr, nullptr); keypad(stdscr, true); /* Use key symbols as KEY_DOWN */ @@ -628,7 +611,7 @@ int cmCursesMainForm::Generate() // run the generate process int retVal = this->CMakeInstance->Generate(); - this->CMakeInstance->SetProgressCallback(CM_NULLPTR, CM_NULLPTR); + this->CMakeInstance->SetProgressCallback(nullptr, nullptr); keypad(stdscr, true); /* Use key symbols as KEY_DOWN */ if (retVal != 0 || !this->Errors.empty()) { @@ -877,7 +860,7 @@ void cmCursesMainForm::HandleInput() cmCursesWidget* lbl = reinterpret_cast( 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 +945,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,7 +975,7 @@ void cmCursesMainForm::HandleInput() if (nextCur) { // make the next or prev. current field after deletion - nextCur = CM_NULLPTR; + nextCur = nullptr; std::vector::iterator it; for (it = this->Entries->begin(); it != this->Entries->end(); ++it) { @@ -1041,7 +1024,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( field_userptr(this->Fields[findex - 2])); diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h index e35cf3ed7..7f5b3cad6 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" @@ -27,7 +27,7 @@ class cmCursesMainForm : public cmCursesForm public: cmCursesMainForm(std::vector const& args, int initwidth); - ~cmCursesMainForm() CM_OVERRIDE; + ~cmCursesMainForm() override; /** * Set the widgets which represent the cache entries. @@ -37,13 +37,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 +64,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 +80,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 char* message, const char* title) override; /** * Used to do a configure. If argument is specified, it does only the check diff --git a/Source/CursesDialog/cmCursesOptionsWidget.cxx b/Source/CursesDialog/cmCursesOptionsWidget.cxx index d26a98f86..a8c493380 100644 --- a/Source/CursesDialog/cmCursesOptionsWidget.cxx +++ b/Source/CursesDialog/cmCursesOptionsWidget.cxx @@ -75,9 +75,8 @@ void cmCursesOptionsWidget::SetOption(const std::string& value) this->CurrentOption = 0; // default to 0 index this->SetValue(value); int index = 0; - for (std::vector::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..3e50e2d4c 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" @@ -24,7 +24,7 @@ public: // 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..bfa0ea343 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" @@ -23,9 +23,9 @@ public: * 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..332d2af08 100644 --- a/Source/CursesDialog/cmCursesStandardIncludes.h +++ b/Source/CursesDialog/cmCursesStandardIncludes.h @@ -3,7 +3,7 @@ #ifndef cmCursesStandardIncludes_h #define cmCursesStandardIncludes_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #if defined(__hpux) #define _BOOL_DEFINED 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..90310f612 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" @@ -30,14 +30,14 @@ public: * 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 +59,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..a44c5e6b6 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" diff --git a/Source/CursesDialog/form/.gitattributes b/Source/CursesDialog/form/.gitattributes deleted file mode 100644 index 62d728cf6..000000000 --- a/Source/CursesDialog/form/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* -format.clang-format 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/LexerParser/.gitattributes b/Source/LexerParser/.gitattributes deleted file mode 100644 index 47eedfb4b..000000000 --- a/Source/LexerParser/.gitattributes +++ /dev/null @@ -1,17 +0,0 @@ -/cmCommandArgumentLexer.cxx generated -/cmCommandArgumentLexer.h generated -/cmCommandArgumentParser.cxx generated -/cmCommandArgumentParserTokens.h generated -/cmDependsJavaLexer.cxx generated -/cmDependsJavaLexer.h generated -/cmDependsJavaParser.cxx generated -/cmDependsJavaParserTokens.h generated -/cmExprLexer.cxx generated -/cmExprLexer.h generated -/cmExprParser.cxx generated -/cmExprParserTokens.h generated -/cmFortranLexer.cxx generated -/cmFortranLexer.h generated -/cmFortranParser.cxx generated -/cmFortranParserTokens.h generated -/cmListFileLexer.c generated diff --git a/Source/LexerParser/cmCommandArgumentLexer.cxx b/Source/LexerParser/cmCommandArgumentLexer.cxx index 12dce3758..bf6bc2f1e 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,13 +653,12 @@ 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 */ @@ -480,9 +676,6 @@ Modify cmCommandArgumentLexer.cxx: /*--------------------------------------------------------------------------*/ - -#line 484 "cmCommandArgumentLexer.cxx" - #define INITIAL 0 #define ESCAPES 1 #define NOESCAPES 2 @@ -525,44 +718,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 +763,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 +774,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 +816,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 +829,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 +870,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 +917,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 +953,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 +984,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 +992,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 +1000,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,7 +1008,6 @@ 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)); @@ -833,7 +1017,6 @@ YY_RULE_SETUP 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)); @@ -843,7 +1026,6 @@ YY_RULE_SETUP 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)); @@ -853,7 +1035,6 @@ YY_RULE_SETUP 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 +1043,6 @@ YY_RULE_SETUP YY_BREAK case 8: YY_RULE_SETUP -#line 89 "cmCommandArgumentLexer.in.l" { if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) ) { @@ -874,7 +1054,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,7 +1062,6 @@ 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; @@ -892,7 +1070,6 @@ YY_RULE_SETUP YY_BREAK case 11: YY_RULE_SETUP -#line 109 "cmCommandArgumentLexer.in.l" { //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); yylvalp->str = yyextra->LCURLYVariable; @@ -901,7 +1078,6 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 115 "cmCommandArgumentLexer.in.l" { //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); yylvalp->str = yyextra->BSLASHVariable; @@ -910,7 +1086,6 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 121 "cmCommandArgumentLexer.in.l" { //yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); yylvalp->str = yyextra->BSLASHVariable; @@ -919,10 +1094,8 @@ YY_RULE_SETUP 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 +1115,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 +1175,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 +1229,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 +1243,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 +1272,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 +1308,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 +1341,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 +1355,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 +1397,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 +1426,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 +1464,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 +1481,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 +1519,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 +1559,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 +1584,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 +1623,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 +1661,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 +1682,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 +1691,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 +1713,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 +1722,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 +1742,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 +1754,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 +1773,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 +1792,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 +1802,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 +1816,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 +1876,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 +1906,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 +1915,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 +1928,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 +1941,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 +1950,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 +1959,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 +1969,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 +1979,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 +1989,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 +2004,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 +2019,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 +2049,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 +2073,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 +2102,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 +2111,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 +2135,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 +2175,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 +2187,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 +2197,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 +2219,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) { 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..acf18f3a7 100644 --- a/Source/LexerParser/cmCommandArgumentLexer.in.l +++ b/Source/LexerParser/cmCommandArgumentLexer.in.l @@ -7,13 +7,12 @@ 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 */ @@ -32,6 +31,8 @@ Modify cmCommandArgumentLexer.cxx: /*--------------------------------------------------------------------------*/ %} +%option prefix="cmCommandArgument_yy" + %option reentrant %option noyywrap %option nounput diff --git a/Source/LexerParser/cmDependsJavaLexer.cxx b/Source/LexerParser/cmDependsJavaLexer.cxx index 8159f47bb..36cac61f9 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 ); +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 ); -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 ); +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) -#define YY_FLUSH_BUFFER cmDependsJava_yy_flush_buffer(YY_CURRENT_BUFFER ,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 ); -YY_BUFFER_STATE cmDependsJava_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); -YY_BUFFER_STATE cmDependsJava_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); -YY_BUFFER_STATE cmDependsJava_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); - -void *cmDependsJava_yyalloc (yy_size_t ,yyscan_t yyscanner ); -void *cmDependsJava_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner ); -void cmDependsJava_yyfree (void * ,yyscan_t yyscanner ); - -#define yy_new_buffer cmDependsJava_yy_create_buffer +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,13 +849,12 @@ 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 */ @@ -682,9 +878,6 @@ Modify cmDependsJavaLexer.cxx: /*--------------------------------------------------------------------------*/ - -#line 686 "cmDependsJavaLexer.cxx" - #define INITIAL 0 #define comment 1 #define string 2 @@ -727,44 +920,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 +965,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 +1020,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 +1033,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 +1074,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 +1121,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 +1157,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 +1188,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 +1622,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 +1640,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 +1661,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 +1721,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 +1775,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 +1789,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 +1818,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 +1854,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 +1887,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 +1901,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 +1943,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 +1972,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 +2048,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 +2065,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 +2103,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 +2143,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 +2168,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 +2207,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 +2245,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 +2266,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 +2275,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 +2297,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 +2306,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 +2326,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 +2338,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 +2357,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 +2376,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 +2386,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 +2400,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 +2460,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 +2490,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 +2499,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 +2512,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 +2525,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 +2534,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 +2543,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 +2553,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 +2563,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 +2573,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 +2588,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 +2603,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 +2633,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 +2657,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 +2686,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 +2695,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 +2719,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 +2759,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 +2771,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 +2781,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 +2803,11 @@ 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" 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..01a0fa302 100644 --- a/Source/LexerParser/cmDependsJavaLexer.in.l +++ b/Source/LexerParser/cmDependsJavaLexer.in.l @@ -7,13 +7,12 @@ 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 */ @@ -38,6 +37,8 @@ Modify cmDependsJavaLexer.cxx: /*--------------------------------------------------------------------------*/ %} +%option prefix="cmDependsJava_yy" + %option reentrant %option noyywrap %pointer diff --git a/Source/LexerParser/cmExprLexer.cxx b/Source/LexerParser/cmExprLexer.cxx index fb6f0db98..81a1ec502 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 ); +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 cmExpr_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 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 ); - -#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,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 15 #define YY_END_OF_BUFFER 16 /* 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[23] = +static const flex_int16_t yy_accept[23] = { 0, 0, 0, 16, 15, 6, 8, 13, 14, 4, 2, 3, 5, 1, 15, 15, 9, 7, 10, 1, 11, 12, 0 } ; -static yyconst YY_CHAR yy_ec[256] = +static const YY_CHAR yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -397,27 +596,27 @@ 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[16] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } ; -static yyconst flex_uint16_t yy_base[23] = +static const flex_int16_t yy_base[23] = { 0, 0, 0, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 9, 7, 5, 21, 21, 21, 6, 21, 21, 21 } ; -static yyconst flex_int16_t yy_def[23] = +static const flex_int16_t yy_def[23] = { 0, 22, 1, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 0 } ; -static yyconst flex_uint16_t yy_nxt[37] = +static const flex_int16_t yy_nxt[37] = { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 20, 19, 22, @@ -425,7 +624,7 @@ static yyconst flex_uint16_t yy_nxt[37] = 22, 22, 22, 22, 22, 22 } ; -static yyconst flex_int16_t yy_chk[37] = +static const flex_int16_t yy_chk[37] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 19, 15, 14, 13, 3, @@ -440,8 +639,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,13 +647,12 @@ 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 */ @@ -473,7 +669,6 @@ Modify cmExprLexer.cxx: #include "cmExprParserTokens.h" /*--------------------------------------------------------------------------*/ -#line 476 "cmExprLexer.cxx" #define INITIAL 0 @@ -515,44 +710,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 +755,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 +810,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 +823,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 +864,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 +911,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 */ { @@ -757,9 +947,9 @@ yy_match: { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 23 ) - 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] != 21 ); @@ -788,80 +978,64 @@ 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; } YY_BREAK case 3: YY_RULE_SETUP -#line 44 "cmExprLexer.in.l" { return exp_MINUS; } YY_BREAK case 4: YY_RULE_SETUP -#line 45 "cmExprLexer.in.l" { return exp_TIMES; } YY_BREAK case 5: YY_RULE_SETUP -#line 46 "cmExprLexer.in.l" { return exp_DIVIDE; } YY_BREAK case 6: YY_RULE_SETUP -#line 47 "cmExprLexer.in.l" { return exp_MOD; } YY_BREAK case 7: YY_RULE_SETUP -#line 48 "cmExprLexer.in.l" { return exp_OR; } YY_BREAK case 8: YY_RULE_SETUP -#line 49 "cmExprLexer.in.l" { return exp_AND; } YY_BREAK case 9: YY_RULE_SETUP -#line 50 "cmExprLexer.in.l" { return exp_XOR; } YY_BREAK case 10: YY_RULE_SETUP -#line 51 "cmExprLexer.in.l" { return exp_NOT; } YY_BREAK case 11: YY_RULE_SETUP -#line 52 "cmExprLexer.in.l" { return exp_SHIFTLEFT; } YY_BREAK case 12: YY_RULE_SETUP -#line 53 "cmExprLexer.in.l" { return exp_SHIFTRIGHT; } YY_BREAK case 13: YY_RULE_SETUP -#line 54 "cmExprLexer.in.l" { return exp_OPENPARENT; } YY_BREAK case 14: YY_RULE_SETUP -#line 55 "cmExprLexer.in.l" { return exp_CLOSEPARENT; } YY_BREAK case 15: YY_RULE_SETUP -#line 57 "cmExprLexer.in.l" ECHO; YY_BREAK -#line 864 "cmExprLexer.cxx" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -879,7 +1053,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 +1113,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 +1167,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 +1181,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 +1210,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 +1246,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 +1279,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 +1293,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; @@ -1157,9 +1335,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 23 ) - 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; @@ -1186,9 +1364,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 23 ) - 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 == 22); (void)yyg; @@ -1262,7 +1440,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 +1457,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 +1495,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 +1535,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 +1560,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 +1599,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 +1637,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 +1658,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 +1667,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 +1689,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 +1698,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 +1718,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 +1730,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 +1749,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 +1768,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 +1778,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 +1792,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 +1852,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 +1882,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 +1891,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 +1904,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 +1917,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 +1926,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 +1935,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 +1945,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 +1955,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 +1965,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 +1980,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 +1995,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 +2025,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 +2049,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 +2078,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 +2087,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 +2111,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 +2151,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 +2163,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 +2173,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 +2195,11 @@ 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" 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..e5f177a35 100644 --- a/Source/LexerParser/cmExprLexer.in.l +++ b/Source/LexerParser/cmExprLexer.in.l @@ -7,13 +7,12 @@ 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 */ @@ -32,6 +31,8 @@ Modify cmExprLexer.cxx: /*--------------------------------------------------------------------------*/ %} +%option prefix="cmExpr_yy" + %option reentrant %option noyywrap %pointer diff --git a/Source/LexerParser/cmFortranLexer.cxx b/Source/LexerParser/cmFortranLexer.cxx index 01c09acb7..dec0f5eb3 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 ); +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 ); -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 ); +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) -#define YY_FLUSH_BUFFER cmFortran_yy_flush_buffer(YY_CURRENT_BUFFER ,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 ); -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 ); - -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 ); - -#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, @@ -394,13 +593,13 @@ static yyconst YY_CHAR yy_ec[256] = 13, 14, 1, 15, 1, 1, 1, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 18, 19, 20, 21, 22, 1, 23, 24, 25, 26, 27, 28, - 29, 29, 30, 29, 29, 31, 32, 33, 34, 29, - 29, 35, 36, 37, 38, 29, 29, 29, 29, 29, - 1, 39, 1, 1, 40, 1, 23, 24, 41, 42, + 24, 24, 29, 24, 24, 30, 31, 32, 33, 24, + 24, 34, 35, 36, 37, 24, 24, 24, 24, 24, + 1, 38, 1, 1, 39, 1, 23, 40, 41, 42, - 43, 44, 29, 29, 45, 29, 29, 46, 32, 47, - 34, 29, 29, 35, 48, 37, 49, 29, 29, 29, - 29, 29, 1, 1, 1, 1, 1, 1, 1, 1, + 43, 44, 24, 24, 45, 24, 24, 46, 31, 47, + 33, 24, 24, 34, 48, 36, 49, 24, 24, 24, + 24, 24, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -417,49 +616,49 @@ 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, 6, 1, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 1, 5, + 7, 7, 7, 7, 7, 7, 7, 1, 5, 7, 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, 41, 42, 428, + 43, 42, 91, 119, 97, 157, 455, 206, 245, 468, + 454, 101, 468, 468, 0, 455, 468, 105, 430, 424, + 62, 68, 119, 141, 468, 468, 468, 111, 0, 59, + 98, 88, 415, 109, 158, 468, 0, 162, 293, 0, + 163, 411, 107, 122, 408, 405, 446, 342, 447, 468, + 0, 444, 169, 173, 420, 421, 132, 404, 90, 404, + 179, 185, 191, 227, 295, 397, 0, 146, 178, 149, + + 412, 0, 208, 206, 398, 171, 399, 170, 399, 391, + 387, 422, 417, 221, 468, 374, 365, 347, 347, 334, + 335, 335, 330, 334, 259, 340, 188, 340, 327, 327, + 327, 324, 325, 325, 320, 322, 319, 355, 354, 325, + 327, 468, 468, 310, 309, 309, 300, 301, 273, 273, + 275, 277, 297, 468, 468, 293, 289, 283, 275, 305, + 261, 238, 237, 214, 468, 468, 468, 196, 197, 189, + 277, 181, 0, 274, 112, 468, 468, 105, 103, 311, + 468, 233, 0, 468, 468, 83, 76, 0, 281, 282, + 468, 468, 52, 468, 468, 468, 468, 23, 287, 298, + + 327, 468, 0, 0, 329, 0, 31, 468, 468, 381, + 388, 394, 397, 404, 411, 418, 425, 432 } ; -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,152 +681,126 @@ 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, - 12, 26, 27, 27, 27, 27, 28, 27, 27, 29, - 27, 30, 27, 27, 27, 31, 27, 32, 33, 34, + 12, 26, 27, 27, 27, 27, 28, 27, 29, 27, + 30, 27, 27, 27, 31, 27, 32, 33, 34, 27, 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, + 35, 208, 35, 35, 41, 36, 36, 35, 37, 41, + 35, 42, 43, 36, 41, 202, 42, 43, 44, 38, + 41, 42, 60, 61, 44, 48, 64, 42, 48, 63, + 39, 39, 53, 53, 97, 53, 54, 60, 61, 64, + 55, 63, 65, 66, 201, 65, 39, 39, 68, 49, + + 97, 68, 83, 84, 69, 83, 48, 87, 88, 48, + 50, 89, 95, 100, 90, 95, 51, 198, 52, 45, + 53, 53, 98, 53, 54, 197, 45, 45, 55, 100, + 49, 121, 45, 99, 67, 102, 122, 45, 98, 45, + 45, 50, 92, 53, 193, 92, 93, 51, 192, 52, + 94, 102, 106, 107, 191, 96, 45, 67, 70, 65, + 66, 70, 65, 68, 104, 108, 68, 104, 109, 69, + 83, 84, 71, 83, 114, 125, 118, 114, 71, 119, + 92, 53, 115, 92, 93, 127, 92, 53, 94, 92, + 93, 125, 92, 53, 94, 92, 93, 127, 72, 73, + + 94, 74, 75, 189, 126, 76, 78, 104, 80, 104, + 104, 133, 104, 78, 78, 130, 134, 151, 131, 78, + 126, 78, 114, 103, 78, 114, 78, 78, 92, 53, + 115, 92, 93, 151, 195, 195, 94, 187, 186, 185, + 184, 183, 182, 78, 78, 79, 79, 80, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 81, 79, 79, 79, 79, 79, 79, 81, 81, 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, - 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, + 81, 81, 79, 81, 81, 81, 81, 81, 81, 81, + 81, 81, 81, 81, 70, 149, 95, 70, 171, 95, + + 172, 173, 174, 188, 181, 199, 180, 149, 103, 180, + 190, 200, 180, 203, 171, 180, 172, 173, 174, 188, + 103, 199, 190, 179, 204, 178, 103, 200, 205, 203, + 205, 205, 177, 205, 72, 73, 176, 74, 75, 96, + 204, 76, 78, 175, 80, 206, 170, 206, 169, 78, + 78, 168, 167, 166, 165, 78, 164, 78, 163, 162, + 78, 161, 78, 78, 160, 159, 158, 157, 156, 155, + 154, 153, 152, 150, 148, 147, 146, 145, 144, 78, + 78, 40, 40, 40, 40, 40, 40, 40, 45, 143, + 142, 141, 45, 45, 46, 46, 46, 46, 46, 46, + + 46, 59, 140, 59, 79, 79, 79, 79, 79, 79, + 79, 91, 91, 91, 91, 91, 91, 91, 194, 194, + 194, 139, 194, 194, 194, 196, 138, 196, 137, 196, + 196, 196, 207, 207, 207, 207, 207, 136, 207, 135, + 132, 129, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, - 4, 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, + 4, 207, 2, 4, 7, 2, 4, 6, 6, 8, + 6, 7, 7, 6, 9, 198, 8, 8, 9, 6, + 10, 9, 28, 29, 10, 17, 32, 10, 17, 31, + 6, 6, 18, 18, 60, 18, 18, 28, 29, 32, + 18, 31, 33, 33, 193, 33, 6, 6, 35, 17, + + 60, 35, 42, 42, 35, 42, 48, 51, 51, 48, + 17, 52, 58, 62, 52, 58, 17, 187, 17, 34, + 53, 53, 61, 53, 53, 186, 34, 34, 53, 62, + 48, 89, 34, 61, 34, 64, 89, 34, 61, 34, + 34, 48, 54, 54, 179, 54, 54, 48, 178, 48, + 54, 64, 73, 73, 175, 58, 34, 34, 36, 65, + 65, 36, 65, 68, 71, 74, 68, 71, 74, 68, + 83, 83, 36, 83, 84, 98, 87, 84, 71, 87, + 91, 91, 84, 91, 91, 100, 92, 92, 91, 92, + 92, 98, 93, 93, 92, 93, 93, 100, 36, 36, + + 93, 36, 36, 172, 99, 36, 38, 104, 38, 103, + 104, 108, 103, 38, 38, 106, 108, 127, 106, 38, + 99, 38, 114, 103, 38, 114, 38, 38, 94, 94, + 114, 94, 94, 127, 182, 182, 94, 170, 169, 168, + 164, 163, 162, 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, 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, - 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, + 39, 39, 39, 39, 69, 125, 95, 69, 149, 95, + + 150, 151, 152, 171, 161, 189, 160, 125, 69, 160, + 174, 190, 180, 199, 149, 180, 150, 151, 152, 171, + 160, 189, 174, 159, 200, 158, 180, 190, 201, 199, + 205, 201, 157, 205, 69, 69, 156, 69, 69, 95, + 200, 69, 78, 153, 78, 201, 148, 205, 147, 78, + 78, 146, 145, 144, 141, 78, 140, 78, 139, 138, + 78, 137, 78, 78, 136, 135, 134, 133, 132, 131, + 130, 129, 128, 126, 124, 123, 122, 121, 120, 78, + 78, 210, 210, 210, 210, 210, 210, 210, 211, 119, + 118, 117, 211, 211, 212, 212, 212, 212, 212, 212, + + 212, 213, 116, 213, 214, 214, 214, 214, 214, 214, + 214, 215, 215, 215, 215, 215, 215, 215, 216, 216, + 216, 113, 216, 216, 216, 217, 112, 217, 111, 217, + 217, 217, 218, 218, 218, 218, 218, 110, 218, 109, + 107, 105, 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,14 +828,12 @@ 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 */ @@ -684,9 +853,6 @@ Modify cmFortranLexer.cxx: /*--------------------------------------------------------------------------*/ - -#line 688 "cmFortranLexer.cxx" - #define INITIAL 0 #define free_fmt 1 #define fixed_fmt 2 @@ -731,44 +897,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 +942,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 +997,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 +1010,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 +1051,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 +1101,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 +1138,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 +1169,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 +1177,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 +1184,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 +1194,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 +1214,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 +1222,6 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 96 "cmFortranLexer.in.l" { cmFortranParser_StringAppend(yyextra, yytext[0]); } @@ -1077,24 +1229,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 +1251,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 +1390,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 +1423,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 +1432,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 +1449,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 +1509,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 +1563,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 +1577,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 +1606,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 +1642,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 +1675,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 +1689,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 +1732,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 +1761,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 +1837,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 +1854,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 +1894,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 +1934,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 +1959,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 +1998,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 +2036,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 +2057,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 +2066,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 +2088,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 +2097,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 +2117,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 +2129,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 +2148,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 +2167,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 +2177,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 +2191,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 +2251,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 +2281,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 +2290,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 +2303,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 +2316,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 +2325,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 +2334,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 +2344,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 +2354,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 +2364,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 +2379,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 +2394,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 +2424,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 +2448,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 +2477,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 +2486,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 +2510,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 +2550,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 +2562,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 +2572,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 +2594,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) { 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..9acba4c1f 100644 --- a/Source/LexerParser/cmFortranLexer.in.l +++ b/Source/LexerParser/cmFortranLexer.in.l @@ -17,14 +17,12 @@ 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 */ @@ -45,6 +43,7 @@ Modify cmFortranLexer.cxx: /*--------------------------------------------------------------------------*/ %} +%option prefix="cmFortran_yy" %option reentrant %option noyywrap diff --git a/Source/LexerParser/cmListFileLexer.c b/Source/LexerParser/cmListFileLexer.c index 3dd3b85b9..c6f524c6b 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 ); +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 ); -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 ); +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) -#define YY_FLUSH_BUFFER cmListFileLexer_yy_flush_buffer(YY_CURRENT_BUFFER ,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 ); -YY_BUFFER_STATE cmListFileLexer_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); -YY_BUFFER_STATE cmListFileLexer_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); -YY_BUFFER_STATE cmListFileLexer_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); - -void *cmListFileLexer_yyalloc (yy_size_t ,yyscan_t yyscanner ); -void *cmListFileLexer_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner ); -void cmListFileLexer_yyfree (void * ,yyscan_t yyscanner ); - -#define yy_new_buffer cmListFileLexer_yy_create_buffer +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[81] = { 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, 17, 10, 11, + 8, 10, 12, 9, 24, 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,126 @@ 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, 8 } ; -static yyconst flex_uint16_t yy_base[95] = +static const flex_int16_t yy_base[99] = { 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, + 69, 100, 16, 323, 323, 55, 59, 323, 323, 13, + 115, 0, 323, 52, 323, 323, 21, 51, 0, 323, + 53, 0, 323, 323, 323, 0, 0, 126, 55, 0, + 25, 25, 53, 0, 0, 136, 53, 0, 57, 0, + 0, 42, 50, 323, 0, 43, 0, 146, 160, 45, + 172, 43, 26, 0, 42, 184, 0, 42, 195, 40, + 323, 40, 0, 38, 37, 34, 32, 31, 23, 323, + 211, 219, 227, 235, 243, 251, 259, 267, 274, 281, + 285, 291, 298, 302, 304, 310, 314, 316 } ; -static yyconst flex_int16_t yy_def[95] = +static const flex_int16_t yy_def[99] = { 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 + 80, 1, 81, 81, 82, 82, 83, 83, 84, 84, + 80, 80, 80, 80, 80, 80, 12, 80, 80, 12, + 80, 85, 80, 86, 80, 80, 86, 86, 87, 80, + 80, 87, 80, 80, 80, 88, 12, 89, 12, 90, + 80, 80, 91, 20, 12, 92, 12, 21, 80, 93, + 12, 86, 86, 80, 87, 80, 88, 89, 80, 58, + 89, 94, 80, 59, 91, 92, 59, 66, 92, 95, + 80, 59, 96, 97, 94, 98, 95, 97, 98, 0, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80 } ; -static yyconst flex_uint16_t yy_nxt[253] = +static const flex_int16_t yy_nxt[340] = { 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, 41, 26, 41, + 14, 14, 44, 54, 44, 52, 41, 27, 41, 28, + 25, 66, 26, 35, 35, 63, 63, 49, 49, 58, + 67, 27, 66, 28, 30, 59, 58, 62, 67, 76, + 64, 59, 74, 56, 52, 53, 31, 32, 30, 71, + 70, 64, 62, 56, 53, 53, 43, 42, 80, 80, + 31, 32, 30, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 34, 35, 30, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 34, 35, + + 37, 80, 80, 80, 38, 80, 39, 80, 80, 37, + 37, 37, 37, 40, 37, 45, 80, 80, 80, 46, + 80, 47, 80, 80, 45, 48, 45, 49, 50, 45, + 59, 80, 60, 80, 80, 80, 80, 80, 80, 61, + 67, 80, 68, 80, 80, 80, 80, 80, 80, 69, + 59, 80, 60, 80, 80, 80, 80, 80, 80, 61, + 59, 80, 80, 80, 38, 80, 72, 80, 80, 59, + 59, 59, 59, 73, 59, 58, 80, 58, 80, 58, + 58, 80, 80, 80, 80, 80, 80, 58, 67, 80, + 68, 80, 80, 80, 80, 80, 80, 69, 66, 80, + + 66, 80, 66, 66, 80, 80, 80, 80, 80, 80, + 66, 24, 24, 24, 24, 24, 24, 24, 24, 29, + 29, 29, 29, 29, 29, 29, 29, 33, 33, 33, + 33, 33, 33, 33, 33, 36, 36, 36, 36, 36, + 36, 36, 36, 51, 80, 51, 51, 51, 51, 51, + 51, 52, 80, 52, 80, 52, 52, 52, 52, 55, + 80, 55, 55, 55, 55, 80, 55, 57, 80, 57, + 57, 57, 57, 57, 58, 80, 80, 58, 80, 58, + 58, 37, 80, 37, 37, 37, 37, 37, 37, 65, + 65, 66, 80, 80, 66, 80, 66, 66, 45, 80, + + 45, 45, 45, 45, 45, 45, 75, 75, 77, 77, + 59, 80, 59, 59, 59, 59, 59, 59, 78, 78, + 79, 79, 11, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80 } ; -static yyconst flex_int16_t yy_chk[253] = +static const flex_int16_t yy_chk[340] = { 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, 41, 3, 41, 3, + 4, 79, 4, 9, 10, 42, 63, 42, 63, 78, + 77, 4, 76, 4, 5, 75, 74, 72, 70, 68, + 65, 62, 60, 56, 53, 52, 5, 5, 6, 49, + 47, 43, 39, 31, 28, 24, 17, 16, 11, 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, + 38, 0, 38, 0, 0, 0, 0, 0, 0, 38, + 46, 0, 46, 0, 0, 0, 0, 0, 0, 46, + 58, 0, 58, 0, 0, 0, 0, 0, 0, 58, + 59, 0, 0, 0, 59, 0, 59, 0, 0, 59, + 59, 59, 59, 59, 59, 61, 0, 61, 0, 61, + 61, 0, 0, 0, 0, 0, 0, 61, 66, 0, + 66, 0, 0, 0, 0, 0, 0, 66, 69, 0, + + 69, 0, 69, 69, 0, 0, 0, 0, 0, 0, + 69, 81, 81, 81, 81, 81, 81, 81, 81, 82, + 82, 82, 82, 82, 82, 82, 82, 83, 83, 83, + 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, + 84, 84, 84, 85, 0, 85, 85, 85, 85, 85, + 85, 86, 0, 86, 0, 86, 86, 86, 86, 87, + 0, 87, 87, 87, 87, 0, 87, 88, 0, 88, + 88, 88, 88, 88, 89, 0, 0, 89, 0, 89, + 89, 90, 0, 90, 90, 90, 90, 90, 90, 91, + 91, 92, 0, 0, 92, 0, 92, 92, 93, 0, + + 93, 93, 93, 93, 93, 93, 94, 94, 95, 95, + 96, 0, 96, 96, 96, 96, 96, 96, 97, 97, + 98, 98, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80 } ; /* 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 +751,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,14 +759,12 @@ 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 */ @@ -600,11 +813,6 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer); /*--------------------------------------------------------------------------*/ - - - -#line 606 "cmListFileLexer.c" - #define INITIAL 0 #define STRING 1 #define BRACKET 2 @@ -649,44 +857,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 +902,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 +957,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 +970,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 +1011,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 +1058,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 +1093,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 >= 81 ) + 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] != 323 ); yy_find_action: yy_act = yy_accept[yy_current_state]; @@ -935,7 +1138,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 +1150,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 +1172,6 @@ YY_RULE_SETUP YY_BREAK case 3: YY_RULE_SETUP -#line 111 "cmListFileLexer.in.l" { lexer->column += yyleng; BEGIN(COMMENT); @@ -979,14 +1179,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 +1194,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 +1203,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 +1212,6 @@ YY_RULE_SETUP YY_BREAK case 8: YY_RULE_SETUP -#line 141 "cmListFileLexer.in.l" { /* Handle ]]====]=======]*/ cmListFileLexerAppend(lexer, yytext, yyleng); @@ -1028,7 +1223,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 +1234,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 +1242,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 +1251,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 +1259,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 +1267,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 +1276,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 +1285,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 +1294,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 +1303,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 +1311,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 +1320,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 +1328,6 @@ YY_RULE_SETUP YY_BREAK case 20: YY_RULE_SETUP -#line 228 "cmListFileLexer.in.l" { lexer->column += yyleng; BEGIN(INITIAL); @@ -1154,14 +1336,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 +1350,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 +1359,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 +1368,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 +1376,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 +1393,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 +1453,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 +1507,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 +1521,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 +1550,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 +1586,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 +1619,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 +1633,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 +1665,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 +1674,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 >= 81 ) + 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 +1694,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 +1703,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 >= 81 ) + 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 == 80); (void)yyg; return yy_is_jam ? 0 : yy_current_state; @@ -1605,7 +1784,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 +1801,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 +1846,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 +1886,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 +1911,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 +1950,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 +1988,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 +2009,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 +2018,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 +2040,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 +2049,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 +2069,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 +2081,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 +2100,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 +2119,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 +2129,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 +2143,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 +2203,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 +2233,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 +2242,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 +2255,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 +2268,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 +2277,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 +2286,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 +2296,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 +2306,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 +2316,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 +2331,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 +2346,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 +2376,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 +2400,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 +2429,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 +2438,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 +2462,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 +2502,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 +2514,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 +2524,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 +2546,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..f2fd5389d 100644 --- a/Source/LexerParser/cmListFileLexer.in.l +++ b/Source/LexerParser/cmListFileLexer.in.l @@ -7,14 +7,12 @@ 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 */ @@ -64,6 +62,8 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer); /*--------------------------------------------------------------------------*/ %} +%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\(\)#\\\"[=]|\\.) LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\" %% @@ -113,7 +113,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\" BEGIN(COMMENT); } -.* { +[^\0\n]* { lexer->column += yyleng; } @@ -168,7 +168,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\" BEGIN(BRACKET); } -. { +[^\0\n] { cmListFileLexerAppend(lexer, yytext, yyleng); lexer->column += yyleng; BEGIN(BRACKET); @@ -231,7 +231,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\" return 1; } -. { +[^\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/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index 9e9df781e..b38797bca 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -33,6 +33,12 @@ 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 # Qt5 support is missing there. @@ -65,7 +71,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") diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index 7fa2ac661..bfd43cfde 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -22,19 +22,18 @@ #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] \n" - " cmake-gui [options] " }, - { CM_NULLPTR, CM_NULLPTR } + { nullptr, " cmake-gui [options]\n" + " cmake-gui [options] \n" + " cmake-gui [options] " }, + { 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,6 +44,10 @@ static void cmAddPluginPath(); Q_IMPORT_PLUGIN(QXcbIntegrationPlugin); #endif +#if defined(USE_QWindowsIntegrationPlugin) +Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin); +#endif + int main(int argc, char** argv) { cmsys::Encoding::CommandLineArguments encoding_args = @@ -93,6 +96,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"); diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 57f8e107e..bbb2395b2 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -32,7 +32,7 @@ QCMakeThread::QCMakeThread(QObject* p) : QThread(p) - , CMakeInstance(CM_NULLPTR) + , CMakeInstance(nullptr) { } @@ -48,7 +48,7 @@ void QCMakeThread::run() emit this->cmakeInitialized(); this->exec(); delete this->CMakeInstance; - this->CMakeInstance = CM_NULLPTR; + this->CMakeInstance = nullptr; } CMakeSetupDialog::CMakeSetupDialog() @@ -1195,7 +1195,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..0da28d813 100644 --- a/Source/QtDialog/CMakeSetupDialog.h +++ b/Source/QtDialog/CMakeSetupDialog.h @@ -70,7 +70,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(); diff --git a/Source/QtDialog/Compilers.h b/Source/QtDialog/Compilers.h index 6c8c8f52a..746266cbb 100644 --- a/Source/QtDialog/Compilers.h +++ b/Source/QtDialog/Compilers.h @@ -3,7 +3,7 @@ #ifndef COMPILERS_HPP #define COMPILERS_HPP -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include @@ -13,7 +13,7 @@ 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/FirstConfigure.cxx b/Source/QtDialog/FirstConfigure.cxx index b193a2782..88ce7cb8a 100644 --- a/Source/QtDialog/FirstConfigure.cxx +++ b/Source/QtDialog/FirstConfigure.cxx @@ -301,7 +301,7 @@ QString CrossCompilerSetup::getFindRoot() const void CrossCompilerSetup::setFindRoot(const QString& t) { - return this->crossFindRoot->setText(t); + this->crossFindRoot->setText(t); } int CrossCompilerSetup::getProgramMode() const diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h index e14cdf2c9..3b8cea721 100644 --- a/Source/QtDialog/QCMake.h +++ b/Source/QtDialog/QCMake.h @@ -3,7 +3,7 @@ #ifndef QCMake_h #define QCMake_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmake.h" @@ -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 diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index 08c2d58d5..1b3fb1583 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); @@ -539,7 +539,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 = @@ -642,7 +642,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..b544b8613 100644 --- a/Source/QtDialog/QCMakeWidgets.cxx +++ b/Source/QtDialog/QCMakeWidgets.cxx @@ -57,7 +57,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 +89,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 +97,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..e63c19753 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 #include @@ -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/bindexplib.cxx b/Source/bindexplib.cxx index e96226a4b..2eb47f3e9 100644 --- a/Source/bindexplib.cxx +++ b/Source/bindexplib.cxx @@ -218,7 +218,7 @@ public: * 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; @@ -394,12 +394,10 @@ bool bindexplib::AddDefinitionFile(const char* filename) void bindexplib::WriteFile(FILE* file) { fprintf(file, "EXPORTS \n"); - for (std::set::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::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 #include diff --git a/Source/cmAddCompileOptionsCommand.cxx b/Source/cmAddCompileOptionsCommand.cxx index 21a8012d8..c37fd9a39 100644 --- a/Source/cmAddCompileOptionsCommand.cxx +++ b/Source/cmAddCompileOptionsCommand.cxx @@ -13,9 +13,8 @@ bool cmAddCompileOptionsCommand::InitialPass( return true; } - for (std::vector::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.c_str()); } 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index b5e7c9ea9..7fed52db5 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -31,7 +31,7 @@ bool cmAddCustomCommandCommand::InitialPass( std::string source, target, main_dependency, working, depfile; std::string comment_buffer; - const char* comment = CM_NULLPTR; + const char* comment = nullptr; std::vector depends, outputs, output, byproducts; bool verbatim = false; bool append = false; @@ -68,9 +68,7 @@ bool cmAddCustomCommandCommand::InitialPass( tdoing doing = doing_nothing; - for (unsigned int j = 0; j < args.size(); ++j) { - std::string const& copy = args[j]; - + for (std::string const& copy : args) { if (copy == "SOURCE") { doing = doing_source; } else if (copy == "COMMAND") { @@ -355,12 +353,11 @@ bool cmAddCustomCommandCommand::InitialPass( bool cmAddCustomCommandCommand::CheckOutputs( const std::vector& outputs) { - for (std::vector::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.c_str())) { + std::string e = "attempted to have a file \"" + o + "\" in a source directory as an output of custom command."; this->SetError(e); cmSystemTools::SetFatalErrorOccured(); @@ -368,10 +365,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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; protected: bool CheckOutputs(const std::vector& outputs); diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index 87e114780..a8d5b2edd 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -49,7 +49,7 @@ 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 sources; // Keep track of parser state. 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmAddDefinitionsCommand.cxx b/Source/cmAddDefinitionsCommand.cxx index 9e0607c60..261fb5baa 100644 --- a/Source/cmAddDefinitionsCommand.cxx +++ b/Source/cmAddDefinitionsCommand.cxx @@ -15,9 +15,8 @@ bool cmAddDefinitionsCommand::InitialPass(std::vector const& args, return true; } - for (std::vector::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.c_str()); } 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: bool HandleNameMode(std::vector const& args); diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index 4adfe2328..69d0ed6a4 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -119,7 +120,7 @@ struct cmIsPair }; template -struct cmIsPair > +struct cmIsPair> { enum { @@ -369,8 +370,7 @@ std::string cmWrap(char prefix, Range const& r, char suffix, template 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)); + return std::find_if(r.begin(), r.end(), [&t](T const& i) { return i != t; }); } template @@ -402,4 +402,22 @@ 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 +std::unique_ptr make_unique(Args&&... args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} + +#endif + +} // namespace cm + #endif diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 0f13b114f..02408a1e8 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -146,9 +146,9 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, } if (archive_write_open( - this->Archive, this, CM_NULLPTR, + this->Archive, this, nullptr, reinterpret_cast(&Callback::Write), - CM_NULLPTR) != ARCHIVE_OK) { + nullptr) != ARCHIVE_OK) { this->Error = "archive_write_open: "; this->Error += cm_archive_error_string(this->Archive); return; @@ -224,7 +224,7 @@ 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 += file; diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h index 4c85c0d16..56dce2a45 100644 --- a/Source/cmArchiveWrite.h +++ b/Source/cmArchiveWrite.h @@ -67,13 +67,13 @@ 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; + return this->Okay() ? &cmArchiveWrite::safe_bool_true : nullptr; } /** Returns true if there has been an error. */ 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif 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 #include @@ -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 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..5f54338c2 100644 --- a/Source/cmBuildNameCommand.cxx +++ b/Source/cmBuildNameCommand.cxx @@ -36,7 +36,7 @@ bool cmBuildNameCommand::InitialPass(std::vector 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 = "([^ ]*) [^ ]* ([^ ]*) "; 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 #include @@ -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 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..ec81cb9f2 100644 --- a/Source/cmCLocaleEnvironmentScope.h +++ b/Source/cmCLocaleEnvironmentScope.h @@ -3,7 +3,7 @@ #ifndef cmCLocaleEnvironmentScope_h #define cmCLocaleEnvironmentScope_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx index 4475c5a52..5106f522d 100644 --- a/Source/cmCMakeHostSystemInformationCommand.cxx +++ b/Source/cmCMakeHostSystemInformationCommand.cxx @@ -76,6 +76,55 @@ 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; diff --git a/Source/cmCMakeHostSystemInformationCommand.h b/Source/cmCMakeHostSystemInformationCommand.h index ef6ca3730..bfff8f1a1 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 #include @@ -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 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..bcc41fca9 100644 --- a/Source/cmCMakeMinimumRequired.cxx +++ b/Source/cmCMakeMinimumRequired.cxx @@ -19,10 +19,10 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector 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 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) { diff --git a/Source/cmCMakeMinimumRequired.h b/Source/cmCMakeMinimumRequired.h index 45b6b7885..18d9460ed 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 #include @@ -23,14 +23,14 @@ 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: std::vector UnknownArguments; diff --git a/Source/cmCMakePolicyCommand.h b/Source/cmCMakePolicyCommand.h index 0e88243f5..b18576c67 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 #include @@ -24,14 +24,14 @@ 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: bool HandleSetMode(std::vector const& args); 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 #include -#include 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..e580e044b 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" @@ -29,7 +29,7 @@ public: 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..e1e11afad 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -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, (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 no_byproducts; std::vector 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); } @@ -405,14 +405,8 @@ char CCONV* cmExpandVariablesInString(void* arg, const char* source, { cmMakefile* mf = static_cast(arg); std::string barf = source; - std::string result = mf->ExpandVariablesInString( - barf, (escapeQuotes ? true : false), (atOnly ? true : false)); - char* res = static_cast(malloc(result.size() + 1)); - if (!result.empty()) { - strcpy(res, result.c_str()); - } - res[result.size()] = '\0'; - return res; + std::string result = mf->ExpandVariablesInString(barf, escapeQuotes, atOnly); + return strdup(result.c_str()); } int CCONV cmExecuteCommand(void* arg, const char* name, int numArgs, @@ -443,7 +437,7 @@ void CCONV cmExpandSourceListArguments(void* arg, int numArgs, result.push_back(args[i]); } int resargc = static_cast(result.size()); - char** resargv = CM_NULLPTR; + char** resargv = nullptr; if (resargc) { resargv = (char**)malloc(resargc * sizeof(char*)); } @@ -460,9 +454,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) @@ -482,7 +474,7 @@ int CCONV cmGetTotalArgumentSize(int argc, char** argv) struct cmCPluginAPISourceFile { cmCPluginAPISourceFile() - : RealSourceFile(CM_NULLPTR) + : RealSourceFile(nullptr) { } cmSourceFile* RealSourceFile; @@ -504,8 +496,8 @@ public: typedef derived::value_type value_type; ~cmCPluginAPISourceFileMap() { - for (iterator i = this->begin(); i != this->end(); ++i) { - delete i->second; + for (auto const& i : *this) { + delete i.second; } } }; @@ -513,13 +505,12 @@ 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 +543,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 +553,14 @@ void* CCONV cmAddSource(void* arg, void* arg2) cmMakefile* mf = static_cast(arg); cmCPluginAPISourceFile* osf = static_cast(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::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 +572,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) @@ -763,25 +753,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/cmCTest.cxx b/Source/cmCTest.cxx index e2605561a..4ea14931e 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -11,9 +11,11 @@ #include "cmsys/Process.h" #include "cmsys/String.hxx" #include "cmsys/SystemInformation.hxx" +#include #include #include #include +#include // IWYU pragma: keep #include #include #include @@ -49,7 +51,6 @@ #include "cmVersion.h" #include "cmVersionConfig.h" #include "cmXMLWriter.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(__BEOS__) || defined(__HAIKU__) @@ -66,7 +67,7 @@ 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 @@ -84,7 +85,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; @@ -130,7 +131,7 @@ 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(¤ttime); // return ::CleanString(ctime(¤ttime)); char current_time[1024]; @@ -146,7 +147,7 @@ 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; @@ -156,7 +157,7 @@ std::string cmCTest::GetCostDataFile() static size_t HTTPResponseCallback(void* ptr, size_t size, size_t nmemb, void* data) { - int realsize = (int)(size * nmemb); + int realsize = static_cast(size * nmemb); std::string* response = static_cast(data); const char* chPtr = static_cast(ptr); @@ -190,7 +191,8 @@ int cmCTest::HTTPRequest(std::string url, HTTPMethod method, ::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 + // fall through to append GET fields + CM_FALLTHROUGH; case cmCTest::HTTP_GET: if (!fields.empty()) { url += "?" + fields; @@ -204,7 +206,7 @@ int cmCTest::HTTPRequest(std::string url, HTTPMethod method, // set response options ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPResponseCallback); - ::curl_easy_setopt(curl, CURLOPT_FILE, (void*)&response); + ::curl_easy_setopt(curl, CURLOPT_FILE, &response); ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); CURLcode res = ::curl_easy_perform(curl); @@ -220,12 +222,11 @@ 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]; + for (unsigned char ch : str) { if ((ch > 126 || ch < 32 || ch == '&' || ch == '%' || ch == '+' || ch == '=' || ch == '@') && ch != 9) { - sprintf(buffer, "%02x;", (unsigned int)ch); + sprintf(buffer, "%02x;", static_cast(ch)); ost << buffer; } else { ost << ch; @@ -240,7 +241,7 @@ std::string cmCTest::DecodeURL(const std::string& in) 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); @@ -252,6 +253,7 @@ std::string cmCTest::DecodeURL(const std::string& in) cmCTest::cmCTest() { this->LabelSummary = true; + this->SubprojectSummary = true; this->ParallelLevel = 1; this->ParallelLevelSetInCli = false; this->TestLoad = 0; @@ -279,11 +281,11 @@ cmCTest::cmCTest() this->GlobalTimeout = 0; this->LastStopTimeout = 24 * 60 * 60; this->CompressXMLFiles = false; - this->CTestConfigFile = ""; - this->ScheduleType = ""; - this->StopTime = ""; + this->CTestConfigFile.clear(); + this->ScheduleType.clear(); + this->StopTime.clear(); this->NextDayStopTime = false; - this->OutputLogFile = CM_NULLPTR; + this->OutputLogFile = nullptr; this->OutputLogFileLastTag = -1; this->SuppressUpdatingCTestConfiguration = false; this->DartVersion = 1; @@ -328,10 +330,8 @@ cmCTest::cmCTest() 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->TestingHandlers) { + handler.second->SetCTestInstance(this); } // Make sure we can capture the build tool output. @@ -341,7 +341,7 @@ cmCTest::cmCTest() cmCTest::~cmCTest() { cmDeleteAll(this->TestingHandlers); - this->SetOutputLogFileName(CM_NULLPTR); + this->SetOutputLogFileName(nullptr); } void cmCTest::SetParallelLevel(int level) @@ -421,9 +421,8 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); - if (!this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), - mf.get())) { + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); + if (!this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), &mf)) { cmCTestOptionalLog( this, DEBUG, "Cannot find custom configuration file tree" << std::endl, quiet); @@ -462,7 +461,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) std::string tag; if (createNewTag) { - time_t tctime = time(CM_NULLPTR); + time_t tctime = time(nullptr); if (this->TomorrowTag) { tctime += (24 * 60 * 60); } @@ -477,7 +476,7 @@ 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)) { @@ -487,7 +486,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) } tfin.close(); } - if (tag.empty() || (CM_NULLPTR != command) || this->Parts[PartStart]) { + if (tag.empty() || (nullptr != command) || this->Parts[PartStart]) { cmCTestOptionalLog( this, DEBUG, "TestModel: " << this->GetTestModelString() << std::endl, quiet); @@ -509,7 +508,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) ofs << this->GetTestModelString() << std::endl; } ofs.close(); - if (CM_NULLPTR == command) { + if (nullptr == command) { cmCTestOptionalLog(this, OUTPUT, "Create new tag: " << tag << " - " << this->GetTestModelString() << std::endl, @@ -805,7 +804,7 @@ cmCTestGenericHandler* cmCTest::GetInitializedHandler(const char* handler) cmCTest::t_TestingHandlers::iterator it = this->TestingHandlers.find(handler); if (it == this->TestingHandlers.end()) { - return CM_NULLPTR; + return nullptr; } it->second->Initialize(); return it->second; @@ -816,7 +815,7 @@ cmCTestGenericHandler* cmCTest::GetHandler(const char* handler) cmCTest::t_TestingHandlers::iterator it = this->TestingHandlers.find(handler); if (it == this->TestingHandlers.end()) { - return CM_NULLPTR; + return nullptr; } return it->second; } @@ -970,17 +969,19 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, } std::vector argv; - for (std::vector::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::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); @@ -1004,11 +1005,11 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Each . represents " << tick_len << " bytes of output" << std::endl << " " << std::flush); - while (cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) { + 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); @@ -1040,7 +1041,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, 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); @@ -1104,27 +1105,27 @@ int cmCTest::RunTest(std::vector argv, std::string* output, inst.SetStreams(&oss, &oss); std::vector 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) { + if (strcmp(i, "--build-generator") == 0 && timeout > 0) { args.push_back("--test-timeout"); std::ostringstream msg; msg << timeout; args.push_back(msg.str()); } - args.push_back(argv[i]); + args.push_back(i); } } if (log) { *log << "* Run internal CTest" << std::endl; } - CM_AUTO_PTR saveEnv; + std::unique_ptr saveEnv; if (modifyEnv) { - saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment); + saveEnv = cm::make_unique(); cmSystemTools::AppendEnv(*environment); } @@ -1146,12 +1147,12 @@ int cmCTest::RunTest(std::vector argv, std::string* output, } std::vector tempOutput; if (output) { - *output = ""; + output->clear(); } - CM_AUTO_PTR saveEnv; + std::unique_ptr saveEnv; if (modifyEnv) { - saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment); + saveEnv = cm::make_unique(); cmSystemTools::AppendEnv(*environment); } @@ -1169,7 +1170,7 @@ int cmCTest::RunTest(std::vector argv, std::string* output, 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); @@ -1189,7 +1190,7 @@ int cmCTest::RunTest(std::vector 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()); @@ -1234,7 +1235,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 +1254,7 @@ std::string cmCTest::SafeBuildIdField(const std::string& value) } } - if (safevalue == "") { + if (safevalue.empty()) { safevalue = "(empty)"; } @@ -1345,9 +1346,8 @@ void cmCTest::AddSiteProperties(cmXMLWriter& xml) std::string l = labels; std::vector args; cmSystemTools::ExpandListArgument(l, args); - for (std::vector::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 +1363,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 cmCTest::GetLabelsForSubprojects() +{ + std::string labelsForSubprojects = + this->GetCTestConfiguration("LabelsForSubprojects"); + std::vector subprojects; + cmSystemTools::ExpandListArgument(labelsForSubprojects, subprojects); + + // sort the array + std::sort(subprojects.begin(), subprojects.end()); + // remove duplicates + std::vector::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 @@ -1374,7 +1401,6 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml, { std::string buildname = cmCTest::SafeBuildIdField(this->GetCTestConfiguration("BuildName")); - cmCTest::VectorOfStrings::const_iterator it; xml.StartDocument(); xml.ProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" " @@ -1390,15 +1416,15 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml, this->AddSiteProperties(xml); xml.StartElement("Notes"); - for (it = files.begin(); it != files.end(); it++) { - cmCTestLog(this, OUTPUT, "\tAdd file: " << *it << std::endl); + for (cmsys::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.Attribute("Name", file); xml.Element("Time", cmSystemTools::GetTime()); 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 +1433,9 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml, } ifs.close(); } else { - xml.Content("Problem reading file: " + *it + "\n"); + xml.Content("Problem reading file: " + file + "\n"); cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: " - << *it << " while creating notes" << std::endl); + << file << " while creating notes" << std::endl); } xml.EndElement(); // Text xml.EndElement(); // Note @@ -1491,14 +1517,13 @@ std::string cmCTest::Base64EncodeFile(std::string const& file) bool cmCTest::SubmitExtraFiles(const VectorOfStrings& files) { - VectorOfStrings::const_iterator it; - for (it = files.begin(); it != files.end(); ++it) { - if (!cmSystemTools::FileExists(it->c_str())) { + for (cmsys::String const& file : files) { + if (!cmSystemTools::FileExists(file.c_str())) { cmCTestLog(this, ERROR_MESSAGE, "Cannot find extra file: " - << *it << " to submit." << std::endl;); + << file << " to submit." << std::endl;); return false; } - this->AddSubmitFile(PartExtraFiles, it->c_str()); + this->AddSubmitFile(PartExtraFiles, file.c_str()); } return true; } @@ -1735,7 +1760,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, if (this->CheckArgument(arg, "--timeout") && i < args.size() - 1) { i++; - double timeout = (double)atof(args[i].c_str()); + double timeout = atof(args[i].c_str()); this->GlobalTimeout = timeout; } @@ -1764,6 +1789,9 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, if (this->CheckArgument(arg, "--no-label-summary")) { this->LabelSummary = false; } + if (this->CheckArgument(arg, "--no-subproject-summary")) { + this->SubprojectSummary = false; + } if (this->CheckArgument(arg, "-Q", "--quiet")) { this->Quiet = true; } @@ -2069,10 +2097,8 @@ int cmCTest::Run(std::vector& args, std::string* output) // 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->TestingHandlers) { + if (!handler.second->ProcessCommandLineArguments(arg, i, args)) { cmCTestLog(this, ERROR_MESSAGE, "Problem parsing command line arguments within a handler"); return 0; @@ -2169,11 +2195,9 @@ int cmCTest::ExecuteTests() if (this->ExtraVerbose) { cmCTestLog(this, OUTPUT, "* Extra verbosity turned on" << std::endl); } - cmCTest::t_TestingHandlers::iterator it; - for (it = this->TestingHandlers.begin(); it != this->TestingHandlers.end(); - ++it) { - it->second->SetVerbose(this->ExtraVerbose); - it->second->SetSubmitIndex(this->SubmitIndex); + for (auto& handler : this->TestingHandlers) { + handler.second->SetVerbose(this->ExtraVerbose); + handler.second->SetSubmitIndex(this->SubmitIndex); } this->GetHandler("script")->SetVerbose(this->Verbose); res = this->GetHandler("script")->ProcessHandler(); @@ -2187,14 +2211,12 @@ int cmCTest::ExecuteTests() // 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); + for (auto& handler : this->TestingHandlers) { + handler.second->SetVerbose(this->Verbose); + handler.second->SetSubmitIndex(this->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); @@ -2292,13 +2314,11 @@ 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) { - cmCTestLog(this, DEBUG, - "* Read custom CTest configuration vectors for handler: " - << it->first << " (" << it->second << ")" << std::endl); - it->second->PopulateCustomVectors(mf); + for (auto& handler : this->TestingHandlers) { + cmCTestLog( + this, DEBUG, "* Read custom CTest configuration vectors for handler: " + << handler.first << " (" << handler.second << ")" << std::endl); + handler.second->PopulateCustomVectors(mf); } } @@ -2317,9 +2337,8 @@ void cmCTest::PopulateCustomVector(cmMakefile* mf, const std::string& def, vec.clear(); cmSystemTools::ExpandListArgument(dval, vec); - for (std::vector::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); } } @@ -2352,7 +2371,7 @@ std::string cmCTest::GetShortPathToFile(const char* cfname) 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 @@ -2402,7 +2421,7 @@ void cmCTest::EmptyCTestConfiguration() void cmCTest::DetermineNextDayStop() { struct tm* lctime; - time_t current_time = time(CM_NULLPTR); + time_t current_time = time(nullptr); lctime = gmtime(¤t_time); int gm_hour = lctime->tm_hour; time_t gm_time = mktime(lctime); @@ -2486,7 +2505,7 @@ bool cmCTest::GetProduceXML() const char* cmCTest::GetSpecificTrack() { if (this->SpecificTrack.empty()) { - return CM_NULLPTR; + return nullptr; } return this->SpecificTrack.c_str(); } @@ -2494,7 +2513,7 @@ const char* cmCTest::GetSpecificTrack() void cmCTest::SetSpecificTrack(const char* track) { if (!track) { - this->SpecificTrack = ""; + this->SpecificTrack.clear(); return; } this->SpecificTrack = track; @@ -2546,25 +2565,19 @@ 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 const& args, + std::string* stdOut, std::string* stdErr, int* retVal, + const char* dir, double timeout, Encoding encoding) { - std::vector args = cmSystemTools::ParseArguments(command); - - if (args.empty()) { - return false; - } - std::vector argv; - for (std::vector::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()); @@ -2584,7 +2597,7 @@ 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); @@ -2608,7 +2621,7 @@ bool cmCTest::RunCommand(const char* command, std::string* stdOut, } } - cmsysProcess_WaitForExit(cp, CM_NULLPTR); + cmsysProcess_WaitForExit(cp, nullptr); if (!tempOutput.empty()) { processOutput.DecodeText(tempOutput, tempOutput); stdOut->append(&*tempOutput.begin(), tempOutput.size()); @@ -2652,7 +2665,7 @@ void cmCTest::SetOutputLogFileName(const char* name) { if (this->OutputLogFile) { delete this->OutputLogFile; - this->OutputLogFile = CM_NULLPTR; + this->OutputLogFile = nullptr; } if (name) { this->OutputLogFile = new cmGeneratedFileStream(name); @@ -2666,7 +2679,7 @@ static const char* cmCTestStringLogType[] = { "DEBUG", "HANDLER_VERBOSE_OUTPUT", "WARNING", "ERROR_MESSAGE", - CM_NULLPTR }; + nullptr }; #define cmCTestLogOutputFileLine(stream) \ if (this->ShowLineNumbers) { \ diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 60f3295e7..dbd67dc68 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -3,7 +3,7 @@ #ifndef cmCTest_h #define cmCTest_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmProcessOutput.h" #include "cmsys/String.hxx" @@ -95,7 +95,7 @@ public: typedef std::set SetOfStrings; /** Process Command line arguments */ - int Run(std::vector&, std::string* output = CM_NULLPTR); + int Run(std::vector&, std::string* output = nullptr); /** * Initialize and finalize testing @@ -245,15 +245,10 @@ 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 const& args, std::string* stdOut, + std::string* stdErr, int* retVal = nullptr, + const char* dir = nullptr, double timeout = 0.0, Encoding encoding = cmProcessOutput::Auto); /** @@ -438,7 +433,9 @@ public: this->StreamErr = err; } void AddSiteProperties(cmXMLWriter& xml); + bool GetLabelSummary() { return this->LabelSummary; } + bool GetSubprojectSummary() { return this->SubprojectSummary; } std::string GetCostDataFile(); @@ -453,6 +450,9 @@ public: /** Return true if test should run until fail */ bool GetRepeatUntilFail() { return this->RepeatUntilFail; } + void GenerateSubprojectsOutput(cmXMLWriter& xml); + std::vector GetLabelsForSubprojects(); + private: int RepeatTests; bool RepeatUntilFail; @@ -464,6 +464,7 @@ private: bool ExtraVerbose; bool ProduceXML; bool LabelSummary; + bool SubprojectSummary; bool UseHTTP10; bool PrintLabels; bool Failover; @@ -571,7 +572,7 @@ private: /** 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 const& process_output); diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 0b025ab6f..44095ec14 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -173,7 +173,7 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal, } const char* cmCacheManager::PersistentProperties[] = { "ADVANCED", "MODIFIED", - "STRINGS", CM_NULLPTR }; + "STRINGS", nullptr }; bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey, CacheEntry& e) @@ -297,10 +297,8 @@ bool cmCacheManager::SaveCache(const std::string& path) fout << "########################\n"; fout << "\n"; - for (std::map::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) { /* @@ -315,7 +313,7 @@ bool cmCacheManager::SaveCache(const std::string& path) } else { cmCacheManager::OutputHelpString(fout, "Missing description"); } - this->OutputKey(fout, i->first); + this->OutputKey(fout, i.first); fout << ":" << cmState::CacheEntryTypeToString(t) << "="; this->OutputValue(fout, ce.Value); fout << "\n\n"; @@ -440,7 +438,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) @@ -455,18 +453,16 @@ const char* cmCacheManager::GetInitializedCacheValue( if (i != this->Cache.end() && i->second.Initialized) { return i->second.Value.c_str(); } - return CM_NULLPTR; + return nullptr; } void cmCacheManager::PrintCache(std::ostream& out) const { out << "=================================================" << std::endl; out << "CMakeCache Contents:" << std::endl; - for (std::map::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 +480,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,11 +490,10 @@ void cmCacheManager::AddCacheEntry(const std::string& key, const char* value, cmSystemTools::ExpandListArgument(e.Value, paths); const char* sep = ""; e.Value = ""; - for (std::vector::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 { @@ -548,7 +543,7 @@ void cmCacheManager::CacheIterator::SetValue(const char* value) entry->Value = value; entry->Initialized = true; } else { - entry->Value = ""; + entry->Value.clear(); } } @@ -610,7 +605,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 +642,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..e9e6570ef 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -117,7 +117,7 @@ public: void PrintCache(std::ostream&) const; ///! Get the iterator for an entry with a given key. - cmCacheManager::CacheIterator GetCacheIterator(const char* key = CM_NULLPTR); + cmCacheManager::CacheIterator GetCacheIterator(const char* key = nullptr); ///! Remove an entry from the cache void RemoveCacheEntry(const std::string& key); @@ -132,7 +132,7 @@ public: { cmCacheManager::CacheIterator it = this->GetCacheIterator(key.c_str()); if (it.IsAtEnd()) { - return CM_NULLPTR; + return nullptr; } return it.GetValue(); } @@ -175,8 +175,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, diff --git a/Source/cmCallVisualStudioMacro.h b/Source/cmCallVisualStudioMacro.h index ad35d306a..fdc9e6646 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 diff --git a/Source/cmCommand.h b/Source/cmCommand.h index ad72fe208..2cc0b88ec 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 #include @@ -31,7 +31,7 @@ public: * Construct the command. By default it has no makefile. */ cmCommand() - : Makefile(CM_NULLPTR) + : Makefile(nullptr) { } diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index 4eb4531f6..6ae58d67a 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -19,7 +19,7 @@ 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, "${"); @@ -88,13 +88,13 @@ char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key, 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) { if (!var) { - return CM_NULLPTR; + return nullptr; } if (this->FileLine >= 0 && strcmp(var, "CMAKE_CURRENT_LIST_LINE") == 0) { std::ostringstream ostr; @@ -117,7 +117,7 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var) this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); } } - return CM_NULLPTR; + return nullptr; } if (this->EscapeQuotes && value) { return this->AddString(cmSystemTools::EscapeQuotes(value)); @@ -169,7 +169,7 @@ 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(strlen(str)); } @@ -234,7 +234,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); @@ -258,8 +258,8 @@ int cmCommandArgumentParserHelper::ParseString(const char* str, int verb) void cmCommandArgumentParserHelper::CleanupParser() { std::vector::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()); } @@ -298,7 +298,7 @@ void cmCommandArgumentParserHelper::SetMakefile(const cmMakefile* mf) 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..cb2a39074 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 #include diff --git a/Source/cmCommandArgumentsHelper.cxx b/Source/cmCommandArgumentsHelper.cxx index babddbe94..968b17cb9 100644 --- a/Source/cmCommandArgumentsHelper.cxx +++ b/Source/cmCommandArgumentsHelper.cxx @@ -11,11 +11,11 @@ cmCommandArgument::cmCommandArgument(cmCommandArgumentsHelper* args, , ArgumentsBeforeEmpty(true) , CurrentIndex(0) { - if (args != CM_NULLPTR) { + if (args != nullptr) { args->AddArgument(this); } - if (this->Group != CM_NULLPTR) { + if (this->Group != nullptr) { this->Group->ContainedArguments.push_back(this); } } @@ -35,7 +35,7 @@ void cmCommandArgument::Follows(const cmCommandArgument* arg) void cmCommandArgument::FollowsGroup(const cmCommandArgumentGroup* group) { - if (group != CM_NULLPTR) { + if (group != nullptr) { this->ArgumentsBeforeEmpty = false; this->ArgumentsBefore.insert(group->ContainedArguments.begin(), group->ContainedArguments.end()); @@ -52,7 +52,7 @@ bool cmCommandArgument::MayFollow(const cmCommandArgument* current) const bool cmCommandArgument::KeyMatches(const std::string& key) const { - if ((this->Key == CM_NULLPTR) || (this->Key[0] == '\0')) { + if ((this->Key == nullptr) || (this->Key[0] == '\0')) { return true; } return (key == this->Key); @@ -60,12 +60,10 @@ bool cmCommandArgument::KeyMatches(const std::string& key) const void cmCommandArgument::ApplyOwnGroup() { - if (this->Group != CM_NULLPTR) { - for (std::vector::const_iterator it = - this->Group->ContainedArguments.begin(); - it != this->Group->ContainedArguments.end(); ++it) { - if (*it != this) { - this->ArgumentsBefore.insert(*it); + if (this->Group != nullptr) { + for (cmCommandArgument* cargs : this->Group->ContainedArguments) { + if (cargs != this) { + this->ArgumentsBefore.insert(cargs); } } } @@ -88,9 +86,9 @@ cmCAStringVector::cmCAStringVector(cmCommandArgumentsHelper* args, const char* key, cmCommandArgumentGroup* group) : cmCommandArgument(args, key, group) - , Ignore(CM_NULLPTR) + , Ignore(nullptr) { - if ((key == CM_NULLPTR) || (*key == 0)) { + if ((key == nullptr) || (*key == 0)) { this->DataStart = 0; } else { this->DataStart = 1; @@ -100,7 +98,7 @@ cmCAStringVector::cmCAStringVector(cmCommandArgumentsHelper* args, bool cmCAStringVector::DoConsume(const std::string& arg, unsigned int index) { if (index >= this->DataStart) { - if ((this->Ignore == CM_NULLPTR) || (arg != this->Ignore)) { + if ((this->Ignore == nullptr) || (arg != this->Ignore)) { this->Vector.push_back(arg); } } @@ -117,7 +115,7 @@ cmCAString::cmCAString(cmCommandArgumentsHelper* args, const char* key, cmCommandArgumentGroup* group) : cmCommandArgument(args, key, group) { - if ((key == CM_NULLPTR) || (*key == 0)) { + if ((key == nullptr) || (*key == 0)) { this->DataStart = 0; } else { this->DataStart = 1; @@ -135,7 +133,7 @@ bool cmCAString::DoConsume(const std::string& arg, unsigned int index) void cmCAString::DoReset() { - this->String = ""; + this->String.clear(); } cmCAEnabler::cmCAEnabler(cmCommandArgumentsHelper* args, const char* key, @@ -180,60 +178,50 @@ void cmCADisabler::DoReset() void cmCommandArgumentGroup::Follows(const cmCommandArgument* arg) { - for (std::vector::iterator it = - this->ContainedArguments.begin(); - it != this->ContainedArguments.end(); ++it) { - (*it)->Follows(arg); + for (cmCommandArgument* ca : this->ContainedArguments) { + ca->Follows(arg); } } void cmCommandArgumentGroup::FollowsGroup(const cmCommandArgumentGroup* group) { - for (std::vector::iterator it = - this->ContainedArguments.begin(); - it != this->ContainedArguments.end(); ++it) { - (*it)->FollowsGroup(group); + for (cmCommandArgument* ca : this->ContainedArguments) { + ca->FollowsGroup(group); } } void cmCommandArgumentsHelper::Parse(const std::vector* args, std::vector* unconsumedArgs) { - if (args == CM_NULLPTR) { + if (args == nullptr) { return; } - for (std::vector::iterator argIt = - this->Arguments.begin(); - argIt != this->Arguments.end(); ++argIt) { - (*argIt)->ApplyOwnGroup(); - (*argIt)->Reset(); + for (cmCommandArgument* ca : this->Arguments) { + ca->ApplyOwnGroup(); + ca->Reset(); } - cmCommandArgument* activeArgument = CM_NULLPTR; - const cmCommandArgument* previousArgument = CM_NULLPTR; - for (std::vector::const_iterator it = args->begin(); - it != args->end(); ++it) { - for (std::vector::iterator argIt = - this->Arguments.begin(); - argIt != this->Arguments.end(); ++argIt) { - if ((*argIt)->KeyMatches(*it) && - ((*argIt)->MayFollow(previousArgument))) { - activeArgument = *argIt; + cmCommandArgument* activeArgument = nullptr; + const cmCommandArgument* previousArgument = nullptr; + for (std::string const& it : *args) { + for (cmCommandArgument* ca : this->Arguments) { + if (ca->KeyMatches(it) && (ca->MayFollow(previousArgument))) { + activeArgument = ca; activeArgument->Activate(); break; } } if (activeArgument) { - bool argDone = activeArgument->Consume(*it); + bool argDone = activeArgument->Consume(it); previousArgument = activeArgument; if (argDone) { - activeArgument = CM_NULLPTR; + activeArgument = nullptr; } } else { - if (unconsumedArgs != CM_NULLPTR) { - unconsumedArgs->push_back(*it); + if (unconsumedArgs != nullptr) { + unconsumedArgs->push_back(it); } } } diff --git a/Source/cmCommandArgumentsHelper.h b/Source/cmCommandArgumentsHelper.h index 44db374d6..d3f102c29 100644 --- a/Source/cmCommandArgumentsHelper.h +++ b/Source/cmCommandArgumentsHelper.h @@ -3,7 +3,7 @@ #ifndef cmCommandArgumentsHelper_h #define cmCommandArgumentsHelper_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -38,7 +38,7 @@ class cmCommandArgument { public: cmCommandArgument(cmCommandArgumentsHelper* args, const char* key, - cmCommandArgumentGroup* group = CM_NULLPTR); + cmCommandArgumentGroup* group = nullptr); virtual ~cmCommandArgument() {} /// this argument may follow after arg. 0 means it comes first. @@ -90,7 +90,7 @@ class cmCAStringVector : public cmCommandArgument { public: cmCAStringVector(cmCommandArgumentsHelper* args, const char* key, - cmCommandArgumentGroup* group = CM_NULLPTR); + cmCommandArgumentGroup* group = nullptr); /// Return the vector of strings const std::vector& GetVector() const { return this->Vector; } @@ -103,8 +103,8 @@ private: unsigned int DataStart; const char* Ignore; cmCAStringVector(); - bool DoConsume(const std::string& arg, unsigned int index) CM_OVERRIDE; - void DoReset() CM_OVERRIDE; + bool DoConsume(const std::string& arg, unsigned int index) override; + void DoReset() override; }; /** cmCAString is to be used for arguments which consist of one value, @@ -113,7 +113,7 @@ class cmCAString : public cmCommandArgument { public: cmCAString(cmCommandArgumentsHelper* args, const char* key, - cmCommandArgumentGroup* group = CM_NULLPTR); + cmCommandArgumentGroup* group = nullptr); /// Return the string const std::string& GetString() const { return this->String; } @@ -121,8 +121,8 @@ public: private: std::string String; unsigned int DataStart; - bool DoConsume(const std::string& arg, unsigned int index) CM_OVERRIDE; - void DoReset() CM_OVERRIDE; + bool DoConsume(const std::string& arg, unsigned int index) override; + void DoReset() override; cmCAString(); }; @@ -132,14 +132,14 @@ class cmCAEnabler : public cmCommandArgument { public: cmCAEnabler(cmCommandArgumentsHelper* args, const char* key, - cmCommandArgumentGroup* group = CM_NULLPTR); + cmCommandArgumentGroup* group = nullptr); /// Has it been enabled ? bool IsEnabled() const { return this->Enabled; } private: bool Enabled; - bool DoConsume(const std::string& arg, unsigned int index) CM_OVERRIDE; - void DoReset() CM_OVERRIDE; + bool DoConsume(const std::string& arg, unsigned int index) override; + void DoReset() override; cmCAEnabler(); }; @@ -149,14 +149,14 @@ class cmCADisabler : public cmCommandArgument { public: cmCADisabler(cmCommandArgumentsHelper* args, const char* key, - cmCommandArgumentGroup* group = CM_NULLPTR); + cmCommandArgumentGroup* group = nullptr); /// Is it still enabled ? bool IsEnabled() const { return this->Enabled; } private: bool Enabled; - bool DoConsume(const std::string& arg, unsigned int index) CM_OVERRIDE; - void DoReset() CM_OVERRIDE; + bool DoConsume(const std::string& arg, unsigned int index) override; + void DoReset() override; cmCADisabler(); }; diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index e1d8ef143..8a7d9bde7 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -42,6 +42,7 @@ #include "cmIfCommand.h" #include "cmIncludeCommand.h" #include "cmIncludeDirectoryCommand.h" +#include "cmIncludeGuardCommand.h" #include "cmIncludeRegularExpressionCommand.h" #include "cmInstallCommand.h" #include "cmInstallFilesCommand.h" @@ -67,7 +68,12 @@ #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" @@ -93,11 +99,6 @@ #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" @@ -132,6 +133,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); @@ -145,8 +147,6 @@ void GetScriptingCommands(cmState* state) state->AddBuiltinCommand("separate_arguments", new cmSeparateArgumentsCommand); state->AddBuiltinCommand("set", new cmSetCommand); - state->AddBuiltinCommand("set_directory_properties", - new cmSetDirectoryPropertiesCommand); state->AddBuiltinCommand("set_property", new cmSetPropertyCommand); state->AddBuiltinCommand("site_name", new cmSiteNameCommand); state->AddBuiltinCommand("string", new cmStringCommand); @@ -229,6 +229,8 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("install_targets", new cmInstallTargetsCommand); state->AddBuiltinCommand("link_directories", new cmLinkDirectoriesCommand); state->AddBuiltinCommand("project", new cmProjectCommand); + state->AddBuiltinCommand("set_directory_properties", + new cmSetDirectoryPropertiesCommand); state->AddBuiltinCommand("set_source_files_properties", new cmSetSourceFilesPropertiesCommand); state->AddBuiltinCommand("set_target_properties", @@ -236,8 +238,17 @@ 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); @@ -258,15 +269,6 @@ void GetProjectCommands(cmState* state) 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, diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index 391d65c40..1189606fc 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 #include #include @@ -22,10 +21,11 @@ cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt) : GeneratorTarget(gt) , Makefile(gt->Makefile) - , LocalGenerator(static_cast(gt->LocalGenerator)) - , GlobalGenerator(static_cast( + , LocalCommonGenerator( + static_cast(gt->LocalGenerator)) + , GlobalCommonGenerator(static_cast( gt->LocalGenerator->GetGlobalGenerator())) - , ConfigName(LocalGenerator->GetConfigName()) + , ConfigName(LocalCommonGenerator->GetConfigName()) { } @@ -62,10 +62,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 +78,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 +90,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 +101,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 +115,11 @@ std::string cmCommonTargetGenerator::GetDefines(const std::string& l) ByLanguageMap::iterator i = this->DefinesByLanguage.find(l); if (i == this->DefinesByLanguage.end()) { std::set 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,10 +147,8 @@ std::vector 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; + 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 @@ -196,11 +194,12 @@ std::string cmCommonTargetGenerator::GetManifests() this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName); std::vector manifests; - for (std::vector::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->ConvertToRelativePath( + this->LocalCommonGenerator->GetWorkingDirectory(), + manifest_src->GetFullPath()), cmOutputConverter::SHELL)); } @@ -233,6 +232,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..9ec98ae8e 100644 --- a/Source/cmComputeComponentGraph.cxx +++ b/Source/cmComputeComponentGraph.cxx @@ -57,8 +57,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 @@ -119,14 +119,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())); + cmGraphEdge(j_component, ni.IsStrong())); } } } diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 9c516ee8d..d9efc2e33 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -194,7 +194,7 @@ cmComputeLinkDepends::cmComputeLinkDepends(const cmGeneratorTarget* target, this->OldLinkDirMode = false; // No computation has been done. - this->CCG = CM_NULLPTR; + this->CCG = nullptr; } cmComputeLinkDepends::~cmComputeLinkDepends() @@ -286,7 +286,7 @@ std::map::iterator cmComputeLinkDepends::AllocateLinkEntry( std::map::iterator lei = this->LinkEntryIndex.insert(index_entry).first; this->EntryList.push_back(LinkEntry()); - this->InferredDependSets.push_back(CM_NULLPTR); + this->InferredDependSets.push_back(nullptr); this->EntryConstraintGraph.push_back(EdgeList()); return lei; } @@ -314,7 +314,7 @@ int cmComputeLinkDepends::AddLinkEntry(cmLinkItem const& item) // 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 _LIB_DEPENDS variable. @@ -357,10 +357,8 @@ void cmComputeLinkDepends::FollowLinkEntry(BFSEntry qe) this->FollowSharedDeps(depender_index, iface); // Support for CMP0003. - for (std::vector::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 const& deps) { - for (std::vector::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); } @@ -445,25 +442,24 @@ void cmComputeLinkDepends::AddVarLinkEntries(int depender_index, std::vector actual_libs; cmTargetLinkLibraryType llt = GENERAL_LibraryType; bool haveLLT = false; - for (std::vector::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 +472,10 @@ 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)); + cmLinkItem item(d, this->FindTargetToLink(depender_index, d)); actual_libs.push_back(item); } else if (this->OldLinkDirMode) { - cmLinkItem item(*di, this->FindTargetToLink(depender_index, *di)); + cmLinkItem item(d, this->FindTargetToLink(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::const_iterator wi = - impl->WrongConfigLibraries.begin(); - wi != impl->WrongConfigLibraries.end(); ++wi) { - this->CheckWrongConfigItem(*wi); + for (cmLinkItem const& wi : impl->WrongConfigLibraries) { + this->CheckWrongConfigItem(wi); } } @@ -514,17 +508,16 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index, std::map dependSets; // Loop over the libraries linked directly by the depender. - for (typename std::vector::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; + cmLinkItem const& item = l; if (item == this->Target->GetName() || item.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) { @@ -535,16 +528,15 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index, } // Update the inferred dependencies for earlier items. - for (std::map::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,9 +548,8 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index, } // Store the inferred dependency sets discovered for this list. - for (std::map::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); } } @@ -608,14 +599,14 @@ void cmComputeLinkDepends::InferDependencies() 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 +651,8 @@ void cmComputeLinkDepends::OrderLinkEntires() } // Start with the original link line. - for (std::vector::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 +674,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]); @@ -771,10 +760,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 +805,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 +821,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::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..dd0e02943 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -40,7 +40,7 @@ public: bool IsFlag; LinkEntry() : Item() - , Target(CM_NULLPTR) + , Target(nullptr) , IsSharedDep(false) , IsFlag(false) { diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index b2deaaa85..fb13a585b 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -260,7 +260,7 @@ cmComputeLinkInformation::cmComputeLinkInformation( 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 +281,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_"; @@ -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,10 +492,7 @@ bool cmComputeLinkInformation::Compute() // directories. std::set const& wrongItems = cld.GetOldWrongConfigItems(); - for (std::set::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 @@ -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::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 libsVec; cmSystemTools::ExpandListArgument(libs, libsVec); - for (std::vector::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); } } } @@ -616,7 +609,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item, // 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 { // Decide whether to use an import library. @@ -710,7 +703,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 +715,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 +734,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 +804,16 @@ void cmComputeLinkInformation::ComputeItemParserInfo() mf->GetDefinition("CMAKE_EXTRA_LINK_EXTENSIONS")) { std::vector linkSuffixVec; cmSystemTools::ExpandListArgument(linkSuffixes, linkSuffixVec); - for (std::vector::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 sharedSuffixVec; cmSystemTools::ExpandListArgument(sharedSuffixes, sharedSuffixVec); - for (std::vector::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 +831,8 @@ void cmComputeLinkInformation::ComputeItemParserInfo() // be the library name. Match index 3 will be the library // extension. reg = "^("; - for (std::set::iterator p = this->LinkPrefixes.begin(); - p != this->LinkPrefixes.end(); ++p) { - reg += *p; + for (std::string const& p : this->LinkPrefixes) { + reg += p; reg += "|"; } reg += ")"; @@ -906,8 +896,7 @@ std::string cmComputeLinkInformation::CreateExtensionRegex( // Build a list of extension choices. std::string libext = "("; const char* sep = ""; - for (std::vector::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,9 +904,9 @@ 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 } @@ -1457,10 +1446,8 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories() } // Add the link directories for full path items. - for (std::vector::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 +1476,17 @@ void cmComputeLinkInformation::PrintLinkPolicyDiagnosis(std::ostream& os) std::string::size_type max_size = 76; std::string line; const char* sep = " "; - for (std::vector::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 +1498,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 emitted; - for (std::vector::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 +1527,8 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo() // and add them to the set if (const char* libraryArch = this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE")) { - for (std::vector::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 +1555,9 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo() } // Store implicit link libraries. - for (std::vector::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); } @@ -1623,7 +1603,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); @@ -1694,10 +1674,9 @@ static void cmCLI_ExpandListUnique(const char* str, { std::vector tmp; cmSystemTools::ExpandListArgument(str, tmp); - for (std::vector::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); } } } @@ -1750,12 +1729,11 @@ void cmComputeLinkInformation::GetRPath(std::vector& runtimeDirs, this->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX"); cmSystemTools::ConvertToUnixSlashes(rootPath); std::vector const& rdirs = this->GetRuntimeSearchPath(); - for (std::vector::const_iterator ri = rdirs.begin(); - ri != rdirs.end(); ++ri) { + 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) { @@ -1773,11 +1751,11 @@ void cmComputeLinkInformation::GetRPath(std::vector& runtimeDirs, 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; + 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) { @@ -1800,12 +1778,11 @@ void cmComputeLinkInformation::GetRPath(std::vector& runtimeDirs, { cmGeneratorTarget::LinkClosure const* lc = this->Target->GetLinkClosure(this->Config); - for (std::vector::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); } diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index 00e3ad265..f8c62145e 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -33,11 +33,11 @@ public: Item() : Value() , IsPath(true) - , Target(CM_NULLPTR) + , Target(nullptr) { } Item(std::string const& v, bool p, - cmGeneratorTarget const* target = CM_NULLPTR) + cmGeneratorTarget const* target = nullptr) : Value(v) , IsPath(p) , Target(target) diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index ff19eac63..963c2df88 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -148,10 +148,10 @@ 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()); } } @@ -160,15 +160,13 @@ void cmComputeTargetDepends::CollectTargets() // Collect all targets from all generators. std::vector const& lgens = this->GlobalGenerator->GetLocalGenerators(); - for (unsigned int i = 0; i < lgens.size(); ++i) { - const std::vector targets = - lgens[i]->GetGeneratorTargets(); - for (std::vector::const_iterator ti = targets.begin(); - ti != targets.end(); ++ti) { - cmGeneratorTarget* gt = *ti; + for (cmLocalGenerator* lgen : lgens) { + const std::vector& targets = + lgen->GetGeneratorTargets(); + for (cmGeneratorTarget const* ti : targets) { int index = static_cast(this->Targets.size()); - this->TargetIndex[gt] = index; - this->Targets.push_back(gt); + this->TargetIndex[ti] = index; + this->Targets.push_back(ti); } } } @@ -204,14 +202,11 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) if (configs.empty()) { configs.push_back(""); } - for (std::vector::const_iterator it = configs.begin(); - it != configs.end(); ++it) { + for (std::string const& it : configs) { std::vector objectFiles; - depender->GetExternalObjects(objectFiles, *it); - for (std::vector::const_iterator oi = - objectFiles.begin(); - oi != objectFiles.end(); ++oi) { - std::string objLib = (*oi)->GetObjectLibrary(); + depender->GetExternalObjects(objectFiles, it); + for (cmSourceFile const* o : objectFiles) { + std::string objLib = o->GetObjectLibrary(); if (!objLib.empty() && emitted.insert(objLib).second) { if (depender->GetType() != cmStateEnums::EXECUTABLE && depender->GetType() != cmStateEnums::STATIC_LIBRARY && @@ -228,17 +223,15 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) } } - 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::const_iterator lib = - impl->Libraries.begin(); - lib != impl->Libraries.end(); ++lib) { + 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); } } } @@ -250,11 +243,10 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) std::set emitted; // A target should not depend on itself. emitted.insert(depender->GetName()); - for (std::set::const_iterator util = tutils.begin(); - util != tutils.end(); ++util) { + 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); } } } @@ -267,13 +259,11 @@ void cmComputeTargetDepends::AddInterfaceDepends( cmGeneratorTarget const* depender = this->Targets[depender_index]; if (cmLinkInterface const* iface = dependee->GetLinkInterface(config, depender)) { - for (std::vector::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) { + this->AddTargetDepend(depender_index, lib, true); + this->AddInterfaceDepends(depender_index, lib, config, emitted); } } } @@ -290,7 +280,7 @@ void cmComputeTargetDepends::AddInterfaceDepends( // within the project. if (dependee && dependee->GetType() == cmStateEnums::EXECUTABLE && !dependee->IsExecutableWithExports()) { - dependee = CM_NULLPTR; + dependee = nullptr; } if (dependee) { @@ -348,7 +338,7 @@ 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) { @@ -365,9 +355,8 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index, // Skip IMPORTED and INTERFACE targets but follow their utility // dependencies. std::set const& utils = dependee->GetUtilityItems(); - for (std::set::const_iterator i = utils.begin(); - i != utils.end(); ++i) { - if (cmGeneratorTarget const* transitive_dependee = i->Target) { + for (cmLinkItem const& i : utils) { + if (cmGeneratorTarget const* transitive_dependee = i.Target) { this->AddTargetDepend(depender_index, transitive_dependee, false); } } @@ -395,11 +384,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 +403,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 +434,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 +454,8 @@ void cmComputeTargetDepends::ComplainAboutBadComponent( std::vector const& components = ccg.GetComponents(); std::vector 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 +464,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"; } } } @@ -514,9 +501,9 @@ bool cmComputeTargetDepends::IntraComponent(std::vector 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()) { + for (cmGraphEdge const& edge : el) { + int j = edge; + if (cmap[j] == c && edge.IsStrong()) { this->FinalGraph[i].push_back(cmGraphEdge(j, true)); if (!this->IntraComponent(cmap, c, j, head, emitted, visited)) { return false; @@ -573,11 +560,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())); + cmGraphEdge(dependee_component_head, ni.IsStrong())); } } return true; diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index 2bacf7321..90b3f6d9a 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmConditionEvaluator.h" -#include "cmConfigure.h" #include "cmsys/RegularExpression.hxx" #include #include @@ -84,7 +83,7 @@ bool cmConditionEvaluator::IsTrue( const std::vector& args, std::string& errorString, cmake::MessageType& status) { - errorString = ""; + errorString.clear(); // handle empty invocation if (args.empty()) { @@ -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()); @@ -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)) { diff --git a/Source/cmConfigure.cmake.h.in b/Source/cmConfigure.cmake.h.in index 524fdf808..9a78aca36 100644 --- a/Source/cmConfigure.cmake.h.in +++ b/Source/cmConfigure.cmake.h.in @@ -19,51 +19,25 @@ #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_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) +#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; + Class(Class const&) = delete; \ + Class& operator=(Class const&) = delete; #endif diff --git a/Source/cmConfigureFileCommand.h b/Source/cmConfigureFileCommand.h index 6cebbd258..cff934b48 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: int ConfigureFile(); diff --git a/Source/cmConnection.cxx b/Source/cmConnection.cxx new file mode 100644 index 000000000..28ba12c4b --- /dev/null +++ b/Source/cmConnection.cxx @@ -0,0 +1,168 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmConnection.h" + +#include "cmServer.h" +#include "cm_uv.h" + +#include +#include + +struct write_req_t +{ + uv_write_t req; + uv_buf_t buf; +}; + +void cmEventBasedConnection::on_alloc_buffer(uv_handle_t* handle, + size_t suggested_size, + uv_buf_t* buf) +{ + (void)(handle); + char* rawBuffer = new char[suggested_size]; + *buf = uv_buf_init(rawBuffer, static_cast(suggested_size)); +} + +void cmEventBasedConnection::on_read(uv_stream_t* stream, ssize_t nread, + const uv_buf_t* buf) +{ + auto conn = reinterpret_cast(stream->data); + if (conn) { + if (nread >= 0) { + conn->ReadData(std::string(buf->base, buf->base + nread)); + } else { + conn->OnDisconnect(static_cast(nread)); + } + } + + delete[](buf->base); +} + +void cmEventBasedConnection::on_close(uv_handle_t* /*handle*/) +{ +} + +void cmEventBasedConnection::on_write(uv_write_t* req, int status) +{ + (void)(status); + + // Free req and buffer + write_req_t* wr = reinterpret_cast(req); + delete[](wr->buf.base); + delete wr; +} + +void cmEventBasedConnection::on_new_connection(uv_stream_t* stream, int status) +{ + (void)(status); + auto conn = reinterpret_cast(stream->data); + + if (conn) { + conn->Connect(stream); + } +} + +bool cmEventBasedConnection::IsOpen() const +{ + return this->WriteStream != nullptr; +} + +void cmEventBasedConnection::WriteData(const std::string& _data) +{ +#ifndef NDEBUG + auto curr_thread_id = uv_thread_self(); + assert(this->Server); + assert(uv_thread_equal(&curr_thread_id, &this->Server->ServeThreadId)); +#endif + + auto data = _data; + assert(this->WriteStream); + if (BufferStrategy) { + data = BufferStrategy->BufferOutMessage(data); + } + + 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(ds)); + memcpy(req->buf.base, data.c_str(), ds); + uv_write(reinterpret_cast(req), + static_cast(this->WriteStream), &req->buf, 1, + on_write); +} + +void cmEventBasedConnection::ReadData(const std::string& data) +{ + this->RawReadBuffer += data; + if (BufferStrategy) { + std::string packet = BufferStrategy->BufferMessage(this->RawReadBuffer); + while (!packet.empty()) { + ProcessRequest(packet); + packet = BufferStrategy->BufferMessage(this->RawReadBuffer); + } + } else { + ProcessRequest(this->RawReadBuffer); + this->RawReadBuffer.clear(); + } +} + +cmEventBasedConnection::cmEventBasedConnection( + cmConnectionBufferStrategy* bufferStrategy) + : BufferStrategy(bufferStrategy) +{ +} + +void cmEventBasedConnection::Connect(uv_stream_t* server) +{ + (void)server; + Server->OnConnected(nullptr); +} + +void cmEventBasedConnection::OnDisconnect(int onerror) +{ + (void)onerror; + this->OnConnectionShuttingDown(); + if (this->Server) { + this->Server->OnDisconnect(this); + } +} + +cmConnection::~cmConnection() +{ +} + +bool cmConnection::OnConnectionShuttingDown() +{ + this->Server = nullptr; + return true; +} + +void cmConnection::SetServer(cmServerBase* s) +{ + Server = s; +} + +void cmConnection::ProcessRequest(const std::string& request) +{ + Server->ProcessRequest(this, request); +} + +bool cmConnection::OnServeStart(std::string* errString) +{ + (void)errString; + return true; +} + +bool cmEventBasedConnection::OnConnectionShuttingDown() +{ + if (this->WriteStream) { + this->WriteStream->data = nullptr; + } + if (this->ReadStream) { + this->ReadStream->data = nullptr; + } + this->ReadStream = nullptr; + this->WriteStream = nullptr; + return true; +} diff --git a/Source/cmConnection.h b/Source/cmConnection.h new file mode 100644 index 000000000..ddb774457 --- /dev/null +++ b/Source/cmConnection.h @@ -0,0 +1,134 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ + +#pragma once + +#include "cmConfigure.h" // IWYU pragma: keep + +#include "cm_uv.h" + +#include +#include +#include + +class cmServerBase; + +/*** + * Given a sequence of bytes with any kind of buffering, instances of this + * class arrange logical chunks according to whatever the use case is for + * the connection. + */ +class cmConnectionBufferStrategy +{ +public: + virtual ~cmConnectionBufferStrategy(); + + /*** + * Called whenever with an active raw buffer. If a logical chunk + * becomes available, that chunk is returned and that portion is + * removed from the rawBuffer + * + * @param rawBuffer in/out parameter. Receive buffer; the buffer strategy is + * free to manipulate this buffer anyway it needs to. + * + * @return Next chunk from the stream. Returns the empty string if a chunk + * isn't ready yet. Users of this interface should repeatedly call this + * function until an empty string is returned since its entirely possible + * multiple chunks come in a single raw buffer. + */ + virtual std::string BufferMessage(std::string& rawBuffer) = 0; + + /*** + * Called to properly buffer an outgoing message. + * + * @param rawBuffer Message to format in the correct way + * + * @return Formatted message + */ + virtual std::string BufferOutMessage(const std::string& rawBuffer) const + { + return rawBuffer; + }; + /*** + * Resets the internal state of the buffering + */ + virtual void clear(); + + // TODO: There should be a callback / flag set for errors +}; + +class cmConnection +{ + CM_DISABLE_COPY(cmConnection) + +public: + cmConnection() {} + + virtual void WriteData(const std::string& data) = 0; + + virtual ~cmConnection(); + + virtual bool OnConnectionShuttingDown(); + + virtual bool IsOpen() const = 0; + + virtual void SetServer(cmServerBase* s); + + virtual void ProcessRequest(const std::string& request); + + virtual bool OnServeStart(std::string* pString); + +protected: + cmServerBase* Server = nullptr; +}; + +/*** + * Abstraction of a connection; ties in event callbacks from libuv and notifies + * the server when appropriate + */ +class cmEventBasedConnection : public cmConnection +{ + +public: + /*** + * @param bufferStrategy If no strategy is given, it will process the raw + * chunks as they come in. The connection + * owns the pointer given. + */ + cmEventBasedConnection(cmConnectionBufferStrategy* bufferStrategy = nullptr); + + virtual void Connect(uv_stream_t* server); + + virtual void ReadData(const std::string& data); + + bool IsOpen() const override; + + void WriteData(const std::string& data) override; + bool OnConnectionShuttingDown() override; + + virtual void OnDisconnect(int errorCode); + uv_stream_t* ReadStream = nullptr; + uv_stream_t* WriteStream = nullptr; + + static void on_close(uv_handle_t* handle); + + template + static void on_close_delete(uv_handle_t* handle) + { + delete reinterpret_cast(handle); + } + +protected: + std::string RawReadBuffer; + + std::unique_ptr BufferStrategy; + + static void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf); + + static void on_write(uv_write_t* req, int status); + + static void on_new_connection(uv_stream_t* stream, int status); + + static void on_alloc_buffer(uv_handle_t* handle, size_t suggested_size, + uv_buf_t* buf); +}; 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 9a4abf3ca..fd258fe79 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 #include @@ -72,7 +71,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, bool isTryRun) { this->BinaryDirectory = argv[1]; - this->OutputFile = ""; + this->OutputFile.clear(); // which signature were we called with ? this->SrcFileSignature = true; @@ -102,7 +101,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, } const char* sourceDirectory = argv[2].c_str(); - const char* projectName = CM_NULLPTR; + const char* projectName = nullptr; std::string targetName; std::vector cmakeFlags(1, "CMAKE_FLAGS"); // fake argv[0] std::vector compileDefs; @@ -418,16 +417,15 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, // Detect languages to enable. cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator(); std::set testLangs; - for (std::vector::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 langs; @@ -468,11 +466,10 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, } std::string projectLangs; - for (std::set::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(), @@ -485,15 +482,14 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, } fprintf(fout, "project(CMAKE_TRY_COMPILE%s)\n", projectLangs.c_str()); fprintf(fout, "set(CMAKE_VERBOSE_MAKEFILE 1)\n"); - for (std::set::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()); + li.c_str(), li.c_str()); } switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0066)) { case cmPolicies::WARN: @@ -523,9 +519,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, static std::string const cfgDefault = "DEBUG"; std::string const cfg = !tcConfig.empty() ? cmSystemTools::UpperCase(tcConfig) : cfgDefault; - for (std::set::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 : "") @@ -639,9 +634,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, cmakeFlags.push_back(flag); } - for (std::set::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); @@ -670,13 +663,12 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, /* Create the actual static library. */ fprintf(fout, "add_library(%s STATIC", targetName.c_str()); } - for (std::vector::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"); @@ -763,9 +755,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, "is not honoring language standard variables in the test project:\n" ; /* clang-format on */ - for (std::vector::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()); } @@ -928,8 +919,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; @@ -964,10 +955,9 @@ void cmCoreTryCompile::FindOutputFile(const std::string& targetName, #endif searchDirs.push_back("/Development"); - for (std::vector::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())) { this->OutputFile = cmSystemTools::CollapseFullPath(command); 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 #include @@ -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 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 +#include // 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::New(const char* algo) +std::unique_ptr cmCryptoHash::New(const char* algo) { if (strcmp(algo, "MD5") == 0) { - return CM_AUTO_PTR(new cmCryptoHash(AlgoMD5)); + return cm::make_unique(AlgoMD5); } if (strcmp(algo, "SHA1") == 0) { - return CM_AUTO_PTR(new cmCryptoHash(AlgoSHA1)); + return cm::make_unique(AlgoSHA1); } if (strcmp(algo, "SHA224") == 0) { - return CM_AUTO_PTR(new cmCryptoHash(AlgoSHA224)); + return cm::make_unique(AlgoSHA224); } if (strcmp(algo, "SHA256") == 0) { - return CM_AUTO_PTR(new cmCryptoHash(AlgoSHA256)); + return cm::make_unique(AlgoSHA256); } if (strcmp(algo, "SHA384") == 0) { - return CM_AUTO_PTR(new cmCryptoHash(AlgoSHA384)); + return cm::make_unique(AlgoSHA384); } if (strcmp(algo, "SHA512") == 0) { - return CM_AUTO_PTR(new cmCryptoHash(AlgoSHA512)); + return cm::make_unique(AlgoSHA512); } if (strcmp(algo, "SHA3_224") == 0) { - return CM_AUTO_PTR(new cmCryptoHash(AlgoSHA3_224)); + return cm::make_unique(AlgoSHA3_224); } if (strcmp(algo, "SHA3_256") == 0) { - return CM_AUTO_PTR(new cmCryptoHash(AlgoSHA3_256)); + return cm::make_unique(AlgoSHA3_256); } if (strcmp(algo, "SHA3_384") == 0) { - return CM_AUTO_PTR(new cmCryptoHash(AlgoSHA3_384)); + return cm::make_unique(AlgoSHA3_384); } if (strcmp(algo, "SHA3_512") == 0) { - return CM_AUTO_PTR(new cmCryptoHash(AlgoSHA3_512)); + return cm::make_unique(AlgoSHA3_512); } - return CM_AUTO_PTR(CM_NULLPTR); + return std::unique_ptr(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::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..1f2a1b52c 100644 --- a/Source/cmCryptoHash.h +++ b/Source/cmCryptoHash.h @@ -3,14 +3,13 @@ #ifndef cmCryptoHash_h #define cmCryptoHash_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep +#include // IWYU pragma: keep #include #include #include -#include "cm_auto_ptr.hxx" - /** * @brief Abstract base class for cryptographic hash generators */ @@ -42,7 +41,7 @@ public: /// 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 New(const char* algo); + static std::unique_ptr 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.h b/Source/cmCurl.h index a2fa4b1c0..0688bb2d7 100644 --- a/Source/cmCurl.h +++ b/Source/cmCurl.h @@ -3,11 +3,11 @@ #ifndef cmCurl_h #define cmCurl_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cm_curl.h" #include -std::string cmCurlSetCAInfo(::CURL* curl, const char* cafile = CM_NULLPTR); +std::string cmCurlSetCAInfo(::CURL* curl, const char* cafile = nullptr); #endif diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 5e377b574..cfd260c23 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -4,8 +4,6 @@ #include "cmMakefile.h" -#include "cmConfigure.h" - cmCustomCommand::cmCustomCommand() : Backtrace() { @@ -30,7 +28,7 @@ cmCustomCommand::cmCustomCommand(cmMakefile const* mf, , Backtrace() , Comment(comment ? comment : "") , WorkingDirectory(workingDirectory ? workingDirectory : "") - , HaveComment(comment != CM_NULLPTR) + , HaveComment(comment != nullptr) , EscapeAllowMakeVars(false) , EscapeOldStyle(true) , CommandExpandLists(false) @@ -62,7 +60,7 @@ 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; } diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 67213ecaa..3d816d562 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -11,9 +11,9 @@ #include "cmOutputConverter.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" -#include "cmConfigure.h" +#include // IWYU pragma: keep +#include cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, const std::string& config, @@ -24,15 +24,13 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, , OldStyle(cc.GetEscapeOldStyle()) , MakeVars(cc.GetEscapeAllowMakeVars()) , GE(new cmGeneratorExpression(cc.GetBacktrace())) - , DependsDone(false) { 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 cge = this->GE->Parse(*clarg); + for (std::string const& clarg : cmdline) { + std::unique_ptr cge = + this->GE->Parse(clarg); std::string parsed_arg = cge->Evaluate(this->LG, this->Config); if (this->CC.GetCommandExpandLists()) { std::vector ExpandedArg; @@ -44,6 +42,20 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, } this->CommandLines.push_back(argv); } + + std::vector depends = this->CC.GetDepends(); + for (std::string const& d : depends) { + std::unique_ptr cge = this->GE->Parse(d); + std::vector result; + cmSystemTools::ExpandListArgument(cge->Evaluate(this->LG, this->Config), + result); + for (std::string& it : result) { + if (cmSystemTools::FileIsFullPath(it.c_str())) { + it = cmSystemTools::CollapseFullPath(it); + } + } + this->Depends.insert(this->Depends.end(), result.begin(), result.end()); + } } cmCustomCommandGenerator::~cmCustomCommandGenerator() @@ -60,7 +72,7 @@ const char* cmCustomCommandGenerator::GetCrossCompilingEmulator( unsigned int c) const { if (!this->LG->GetMakefile()->IsOn("CMAKE_CROSSCOMPILING")) { - return CM_NULLPTR; + return nullptr; } std::string const& argv0 = this->CommandLines[c][0]; cmGeneratorTarget* target = this->LG->FindGeneratorTargetToUse(argv0); @@ -68,7 +80,7 @@ const char* cmCustomCommandGenerator::GetCrossCompilingEmulator( !target->IsImported()) { return target->GetProperty("CROSSCOMPILING_EMULATOR"); } - return CM_NULLPTR; + return nullptr; } const char* cmCustomCommandGenerator::GetArgv0Location(unsigned int c) const @@ -81,7 +93,19 @@ 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 @@ -125,14 +149,13 @@ void cmCustomCommandGenerator::AppendArguments(unsigned int c, std::string& cmd) const { unsigned int offset = 1; - if (this->GetCrossCompilingEmulator(c) != CM_NULLPTR) { + if (this->GetCrossCompilingEmulator(c) != nullptr) { 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; @@ -171,23 +194,5 @@ std::vector const& cmCustomCommandGenerator::GetByproducts() const std::vector const& cmCustomCommandGenerator::GetDepends() const { - if (!this->DependsDone) { - this->DependsDone = true; - std::vector depends = this->CC.GetDepends(); - for (std::vector::const_iterator i = depends.begin(); - i != depends.end(); ++i) { - CM_AUTO_PTR cge = this->GE->Parse(*i); - std::vector result; - cmSystemTools::ExpandListArgument(cge->Evaluate(this->LG, this->Config), - result); - for (std::vector::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..34fd653a5 100644 --- a/Source/cmCustomCommandGenerator.h +++ b/Source/cmCustomCommandGenerator.h @@ -21,9 +21,8 @@ class cmCustomCommandGenerator bool OldStyle; bool MakeVars; cmGeneratorExpression* GE; - mutable bool DependsDone; - mutable std::vector Depends; cmCustomCommandLines CommandLines; + std::vector Depends; const char* GetCrossCompilingEmulator(unsigned int c) const; const char* GetArgv0Location(unsigned int c) const; @@ -41,6 +40,7 @@ public: std::vector const& GetOutputs() const; std::vector const& GetByproducts() const; std::vector 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 #include @@ -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 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..e766854a6 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 #include #include @@ -35,7 +34,7 @@ const char* 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.c_str() : nullptr; } void cmDefinitions::Raise(const std::string& key, StackIter begin, @@ -67,10 +66,9 @@ std::vector cmDefinitions::UnusedKeys() const std::vector 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 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 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..528b15748 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -6,10 +6,10 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include #include #include "cmLinkedTree.h" -#include "cm_unordered_map.hxx" /** \class cmDefinitions * \brief Store a scope of variable definitions for CMake language. @@ -70,7 +70,7 @@ private: }; static Def NoDef; - typedef CM_UNORDERED_MAP MapType; + typedef std::unordered_map 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..cdab671a7 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -18,7 +18,7 @@ cmDepends::cmDepends(cmLocalGenerator* lg, const char* targetDir) : CompileDirectory() , LocalGenerator(lg) , Verbose(false) - , FileComparison(CM_NULLPTR) + , FileComparison(nullptr) , TargetDirectory(targetDir) , MaxPath(16384) , Dependee(new char[MaxPath]) @@ -42,7 +42,7 @@ bool cmDepends::Write(std::ostream& makeDepends, std::ostream& internalDepends) std::vector pairs; cmSystemTools::ExpandListArgument(srcStr, pairs); - std::map > dependencies; + std::map> dependencies; for (std::vector::iterator si = pairs.begin(); si != pairs.end();) { // Get the source and object file. @@ -53,12 +53,10 @@ bool cmDepends::Write(std::ostream& makeDepends, std::ostream& internalDepends) std::string const& obj = *si++; dependencies[obj].insert(src); } - for (std::map >::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; } @@ -125,7 +123,7 @@ bool cmDepends::CheckDependencies( // regenerated. bool okay = true; bool dependerExists = false; - DependencyVector* currentDependencies = CM_NULLPTR; + DependencyVector* currentDependencies = nullptr; while (internalDepends.getline(this->Dependee, this->MaxPath)) { if (this->Dependee[0] == 0 || this->Dependee[0] == '#' || @@ -167,7 +165,7 @@ bool cmDepends::CheckDependencies( bool regenerate = false; const char* dependee = this->Dependee + 1; const char* depender = this->Depender; - if (currentDependencies != CM_NULLPTR) { + if (currentDependencies != nullptr) { currentDependencies->push_back(dependee); } @@ -227,9 +225,9 @@ bool cmDepends::CheckDependencies( // Remove the information of this depender from the map, it needs // to be rescanned - if (currentDependencies != CM_NULLPTR) { + if (currentDependencies != nullptr) { validDeps.erase(this->Depender); - currentDependencies = CM_NULLPTR; + currentDependencies = nullptr; } // Remove the depender to be sure it is rebuilt. @@ -246,7 +244,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..a4fee3c8a 100644 --- a/Source/cmDepends.h +++ b/Source/cmDepends.h @@ -3,7 +3,7 @@ #ifndef cmDepends_h #define cmDepends_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -29,7 +29,7 @@ class cmDepends public: /** Instances need to know the build directory name and the relative path from the build directory to the target file. */ - cmDepends(cmLocalGenerator* lg = CM_NULLPTR, const char* targetDir = ""); + cmDepends(cmLocalGenerator* lg = nullptr, const char* targetDir = ""); /** at what level will the compile be done from */ void SetCompileDirectory(const char* dir) { this->CompileDirectory = dir; } diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx index 2c464cc9c..1ab3fa244 100644 --- a/Source/cmDependsC.cxx +++ b/Source/cmDependsC.cxx @@ -20,7 +20,7 @@ #define INCLUDE_REGEX_TRANSFORM_MARKER "#IncludeRegexTransform: " cmDependsC::cmDependsC() - : ValidDeps(CM_NULLPTR) + : ValidDeps(nullptr) { } @@ -96,7 +96,7 @@ bool cmDependsC::WriteDependencies(const std::set& sources, std::set dependencies; bool haveDeps = false; - if (this->ValidDeps != CM_NULLPTR) { + if (this->ValidDeps != nullptr) { std::map::const_iterator tmpIt = this->ValidDeps->find(obj); if (tmpIt != this->ValidDeps->end()) { @@ -107,15 +107,14 @@ bool cmDependsC::WriteDependencies(const std::set& sources, if (!haveDeps) { // Walk the dependency graph starting with the source file. - int srcFiles = (int)sources.size(); + int srcFiles = static_cast(sources.size()); this->Encountered.clear(); - for (std::set::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 scanned; @@ -150,14 +149,12 @@ bool cmDependsC::WriteDependencies(const std::set& sources, if (headerLocationIt != this->HeaderLocationCache.end()) { fullName = headerLocationIt->second; } else { - for (std::vector::const_iterator i = - this->IncludePath.begin(); - i != this->IncludePath.end(); ++i) { + for (std::string const& i : 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); + cmSystemTools::CollapseCombinedPath(i, current.FileName); // Look for the file in this location. if (cmSystemTools::FileExists(tempPathStr.c_str(), true)) { @@ -189,13 +186,11 @@ bool cmDependsC::WriteDependencies(const std::set& sources, if (fileIt != this->FileCache.end()) { fileIt->second->Used = true; dependencies.insert(fullName); - for (std::vector::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 { @@ -234,14 +229,13 @@ bool cmDependsC::WriteDependencies(const std::set& sources, std::string obj_m = cmSystemTools::ConvertToOutputPath(obj_i.c_str()); internalDepends << obj_i << std::endl; - for (std::set::const_iterator i = dependencies.begin(); - i != dependencies.end(); ++i) { + for (std::string const& dep : dependencies) { makeDepends << obj_m << ": " << cmSystemTools::ConvertToOutputPath( - this->LocalGenerator->ConvertToRelativePath(binDir, *i).c_str()) + this->LocalGenerator->ConvertToRelativePath(binDir, dep).c_str()) << std::endl; - internalDepends << " " << *i << std::endl; + internalDepends << " " << dep << std::endl; } makeDepends << std::endl; @@ -259,12 +253,12 @@ void cmDependsC::ReadCacheFile() } std::string line; - cmIncludeLines* cacheEntry = CM_NULLPTR; + cmIncludeLines* cacheEntry = nullptr; bool haveFileName = false; while (cmSystemTools::GetLineFromStream(fin, line)) { if (line.empty()) { - cacheEntry = CM_NULLPTR; + cacheEntry = nullptr; haveFileName = false; continue; } @@ -302,7 +296,7 @@ void cmDependsC::ReadCacheFile() } } } - } else if (cacheEntry != CM_NULLPTR) { + } else if (cacheEntry != nullptr) { UnscannedEntry entry; entry.FileName = line; if (cmSystemTools::GetLineFromStream(fin, line)) { @@ -330,20 +324,16 @@ void cmDependsC::WriteCacheFile() const cacheOut << this->IncludeRegexComplainString << "\n\n"; cacheOut << this->IncludeRegexTransformString << "\n\n"; - for (std::map::const_iterator fileIt = - this->FileCache.begin(); - fileIt != this->FileCache.end(); ++fileIt) { - if (fileIt->second->Used) { - cacheOut << fileIt->first << std::endl; - - for (std::vector::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; @@ -411,9 +401,8 @@ void cmDependsC::SetupTransforms() if (const char* xform = mf->GetDefinition("CMAKE_INCLUDE_TRANSFORMS")) { cmSystemTools::ExpandListArgument(xform, transformRules, true); } - for (std::vector::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,10 +411,9 @@ 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]*\\(([^),]*)\\)"; @@ -434,12 +422,11 @@ void cmDependsC::SetupTransforms() // 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; } } } diff --git a/Source/cmDependsC.h b/Source/cmDependsC.h index 250d40f8a..2f76f6275 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" @@ -33,13 +33,13 @@ public: const std::map* validDeps); /** Virtual destructor to cleanup subclasses properly. */ - ~cmDependsC() CM_OVERRIDE; + ~cmDependsC() override; protected: // Implement writing/checking methods required by superclass. bool WriteDependencies(const std::set& 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, diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index 8b05fab49..fdbc08627 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -52,7 +52,7 @@ public: }; cmDependsFortran::cmDependsFortran() - : Internal(CM_NULLPTR) + : Internal(nullptr) { } @@ -73,12 +73,10 @@ cmDependsFortran::cmDependsFortran(cmLocalGenerator* lg) // translate i.e. FOO=BAR to FOO and add it to the list of defined // preprocessor symbols - for (std::vector::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); } @@ -105,9 +103,7 @@ bool cmDependsFortran::WriteDependencies(const std::set& sources, } bool okay = true; - for (std::set::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()); @@ -154,9 +150,8 @@ 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, + for (auto const& i : objInfo) { + if (!this->WriteDependenciesReal(i.first.c_str(), i.second, mod_dir, stamp_dir, makeDepends, internalDepends)) { return false; @@ -170,9 +165,8 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends, fiStream << "# The fortran modules provided by this target.\n"; fiStream << "provides\n"; std::set const& provides = this->Internal->TargetProvides; - for (std::set::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. @@ -184,19 +178,18 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends, fcStream << "FILE(REMOVE"; std::string currentBinDir = this->LocalGenerator->GetCurrentBinaryDirectory(); - for (std::set::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 += cmSystemTools::UpperCase(i); mod_upper += ".mod"; std::string mod_lower = mod_dir; mod_lower += "/"; - mod_lower += *i; + mod_lower += i; mod_lower += ".mod"; std::string stamp = stamp_dir; stamp += "/"; - stamp += *i; + stamp += i; stamp += ".mod.stamp"; fcStream << "\n"; fcStream << " \"" @@ -219,16 +212,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::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,9 +238,8 @@ void cmDependsFortran::LocateModules() mf->GetDefinition("CMAKE_TARGET_LINKED_INFO_FILES")) { cmSystemTools::ExpandListArgument(infoFilesValue, infoFiles); } - for (std::vector::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) { @@ -262,9 +252,8 @@ void cmDependsFortran::MatchLocalModules() { const char* stampDir = this->TargetDirectory.c_str(); std::set const& provides = this->Internal->TargetProvides; - for (std::set::const_iterator i = provides.begin(); - i != provides.end(); ++i) { - this->ConsiderModule(i->c_str(), stampDir); + for (std::string const& i : provides) { + this->ConsiderModule(i.c_str(), stampDir); } } @@ -326,35 +315,32 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj, std::string obj_m = cmSystemTools::ConvertToOutputPath(obj_i.c_str()); internalDepends << obj_i << std::endl; internalDepends << " " << src << std::endl; - for (std::set::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).c_str()) << std::endl; - internalDepends << " " << *i << std::endl; + internalDepends << " " << i << std::endl; } makeDepends << std::endl; // Write module requirements to the output stream. - for (std::set::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::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) != + 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 += i; proxy += ".mod.proxy"; proxy = cmSystemTools::ConvertToOutputPath( this->MaybeConvertToRelativePath(binDir, proxy).c_str()); @@ -366,7 +352,7 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj, // 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(); } @@ -379,7 +365,7 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj, // 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()); makeDepends << obj_m << ": " << module << "\n"; @@ -388,11 +374,10 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj, } // Write provided modules to the output stream. - for (std::set::const_iterator i = info.Provides.begin(); - i != info.Provides.end(); ++i) { + for (std::string const& i : info.Provides) { std::string proxy = stamp_dir; proxy += "/"; - proxy += *i; + proxy += i; proxy += ".mod.proxy"; proxy = cmSystemTools::ConvertToOutputPath( this->MaybeConvertToRelativePath(binDir, proxy).c_str()); @@ -404,18 +389,17 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj, // Create a target to copy the module after the object file // changes. makeDepends << obj_m << ".provides.build:\n"; - for (std::set::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 m = cmSystemTools::LowerCase(i); std::string modFile = mod_dir; modFile += "/"; - modFile += *i; + modFile += i; modFile = this->LocalGenerator->ConvertToOutputFormat( this->MaybeConvertToRelativePath(binDir, modFile), cmOutputConverter::SHELL); @@ -462,10 +446,9 @@ bool cmDependsFortran::FindModule(std::string const& name, std::string& module) // Search the include path for the module. std::string fullName; - for (std::vector::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)) { @@ -474,7 +457,7 @@ bool cmDependsFortran::FindModule(std::string const& name, std::string& module) } // Try the upper-case name. - fullName = *i; + fullName = ip; fullName += "/"; fullName += mod_upper; if (cmSystemTools::FileExists(fullName.c_str(), true)) { diff --git a/Source/cmDependsFortran.h b/Source/cmDependsFortran.h index ec208af3a..ccf267b2f 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 #include @@ -35,7 +35,7 @@ public: cmDependsFortran(cmLocalGenerator* lg); /** Virtual destructor to cleanup subclasses properly. */ - ~cmDependsFortran() CM_OVERRIDE; + ~cmDependsFortran() override; /** Callback from build system after a .mod file has been generated by a Fortran90 compiler to copy the .mod file to the @@ -50,7 +50,7 @@ public: 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(); @@ -62,7 +62,7 @@ protected: // Implement writing/checking methods required by superclass. bool WriteDependencies(const std::set& 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, diff --git a/Source/cmDependsJava.h b/Source/cmDependsJava.h index a07bf0979..d070840ad 100644 --- a/Source/cmDependsJava.h +++ b/Source/cmDependsJava.h @@ -3,7 +3,7 @@ #ifndef cmDependsJava_h #define cmDependsJava_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmDepends.h" @@ -25,16 +25,16 @@ public: cmDependsJava(); /** Virtual destructor to cleanup subclasses properly. */ - ~cmDependsJava() CM_OVERRIDE; + ~cmDependsJava() override; protected: // Implement writing/checking methods required by superclass. bool WriteDependencies(const std::set& sources, const std::string& file, std::ostream& makeDepends, - std::ostream& internalDepends) CM_OVERRIDE; + std::ostream& internalDepends) override; bool CheckDependencies( std::istream& internalDepends, const char* internalDependsFileName, - std::map& validDeps) CM_OVERRIDE; + std::map& validDeps) override; }; #endif diff --git a/Source/cmDependsJavaParserHelper.cxx b/Source/cmDependsJavaParserHelper.cxx index 7bc91bfd4..f227cf25b 100644 --- a/Source/cmDependsJavaParserHelper.cxx +++ b/Source/cmDependsJavaParserHelper.cxx @@ -2,8 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmDependsJavaParserHelper.h" -#include "cmConfigure.h" - #include "cmDependsJavaLexer.h" #include "cmSystemTools.h" @@ -42,10 +40,8 @@ void cmDependsJavaParserHelper::CurrentClass::AddFileNamesForPrinting( } rname += this->Name; files->push_back(rname); - std::vector::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 +53,7 @@ void cmDependsJavaParserHelper::DeallocateParserType(char** pt) if (!*pt) { return; } - *pt = CM_NULLPTR; + *pt = nullptr; this->UnionsAvailable--; } @@ -66,9 +62,8 @@ void cmDependsJavaParserHelper::AddClassFound(const char* sclass) if (!sclass) { return; } - std::vector::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; } } @@ -77,10 +72,8 @@ void cmDependsJavaParserHelper::AddClassFound(const char* sclass) void cmDependsJavaParserHelper::AddPackagesImport(const char* sclass) { - std::vector::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; } } @@ -96,9 +89,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(ch); } else { - std::cout << "<" << (int)ch << ">"; + std::cout << "<" << static_cast(ch) << ">"; break; } } @@ -158,15 +151,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(strlen(str)); } if (len == 0) { return; @@ -210,10 +203,8 @@ void cmDependsJavaParserHelper::PrintClasses() std::cerr << "Error when parsing. No classes on class stack" << std::endl; abort(); } - std::vector files = this->GetFilesProduced(); - std::vector::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 +212,8 @@ std::vector cmDependsJavaParserHelper::GetFilesProduced() { std::vector files; CurrentClass const& toplevel = this->ClassStack.front(); - std::vector::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 +253,8 @@ int cmDependsJavaParserHelper::ParseString(const char* str, int verb) std::cout << std::endl; std::cout << "Depends on:"; if (!this->ClassesFound.empty()) { - std::vector::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 +271,8 @@ int cmDependsJavaParserHelper::ParseString(const char* str, int verb) void cmDependsJavaParserHelper::CleanupParser() { - std::vector::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()); } @@ -324,7 +310,7 @@ void cmDependsJavaParserHelper::Error(const char* str) 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/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 #include @@ -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 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..0c9686087 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -41,12 +41,12 @@ static const char* cmDocumentationStandardOptions[][2] = { { "--help-variable-list []", "List variables with help available and exit." }, { "--help-variables []", "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 } + { nullptr, "The following generators are available on this platform:" }, + { nullptr, nullptr } }; cmDocumentation::cmDocumentation() @@ -123,23 +123,21 @@ bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os) bool result = true; // Loop over requested documentation types. - for (std::vector::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; } } @@ -394,16 +392,14 @@ void cmDocumentation::SetSection(const char* name, const char* docs[][2]) void cmDocumentation::SetSections( std::map& sections) { - for (std::map::const_iterator it = - sections.begin(); - it != sections.end(); ++it) { - this->SetSection(it->first.c_str(), it->second); + for (auto const& s : sections) { + this->SetSection(s.first.c_str(), s.second); } } void cmDocumentation::PrependSection(const char* name, const char* docs[][2]) { - cmDocumentationSection* sec = CM_NULLPTR; + cmDocumentationSection* sec = nullptr; if (this->AllSections.find(name) == this->AllSections.end()) { sec = new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); @@ -417,7 +413,7 @@ void cmDocumentation::PrependSection(const char* name, const char* docs[][2]) void cmDocumentation::PrependSection(const char* name, std::vector& docs) { - cmDocumentationSection* sec = CM_NULLPTR; + cmDocumentationSection* sec = nullptr; if (this->AllSections.find(name) == this->AllSections.end()) { sec = new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); @@ -430,7 +426,7 @@ void cmDocumentation::PrependSection(const char* name, void cmDocumentation::AppendSection(const char* name, const char* docs[][2]) { - cmDocumentationSection* sec = CM_NULLPTR; + cmDocumentationSection* sec = nullptr; if (this->AllSections.find(name) == this->AllSections.end()) { sec = new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); @@ -444,7 +440,7 @@ void cmDocumentation::AppendSection(const char* name, const char* docs[][2]) void cmDocumentation::AppendSection(const char* name, std::vector& docs) { - cmDocumentationSection* sec = CM_NULLPTR; + cmDocumentationSection* sec = nullptr; if (this->AllSections.find(name) == this->AllSections.end()) { sec = new cmDocumentationSection(name, cmSystemTools::UpperCase(name).c_str()); @@ -489,10 +485,9 @@ void cmDocumentation::PrintNames(std::ostream& os, std::string const& pattern) std::vector files; this->GlobHelp(files, pattern); std::vector names; - for (std::vector::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 +496,8 @@ void cmDocumentation::PrintNames(std::ostream& os, std::string const& pattern) } } std::sort(names.begin(), names.end()); - for (std::vector::iterator i = names.begin(); i != names.end(); - ++i) { - os << *i << "\n"; + for (std::string const& n : names) { + os << n << "\n"; } } @@ -514,9 +508,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::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 +579,13 @@ bool cmDocumentation::PrintHelpListModules(std::ostream& os) std::vector files; this->GlobHelp(files, "module/*"); std::vector modules; - for (std::vector::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::iterator i = modules.begin(); - i != modules.end(); ++i) { - os << *i << "\n"; + for (std::string const& m : modules) { + os << m << "\n"; } return true; } diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index 2866fef03..c80bed1cd 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -3,7 +3,7 @@ #ifndef _cmDocumentation_h #define _cmDocumentation_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmDocumentationFormatter.h" @@ -32,7 +32,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 diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 001826318..6b996e4b0 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -168,26 +168,25 @@ void cmDocumentationFormatter::PrintSection( os << section.GetName() << "\n"; const std::vector& entries = section.GetEntries(); - for (std::vector::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 << " " << entry.Name; this->TextIndent = " "; int align = static_cast(strlen(this->TextIndent)) - 4; - for (int i = static_cast(op->Name.size()); i < align; ++i) { + for (int i = static_cast(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/cmDynamicLoader.cxx b/Source/cmDynamicLoader.cxx index 7fbe75c7b..7da6ff54b 100644 --- a/Source/cmDynamicLoader.cxx +++ b/Source/cmDynamicLoader.cxx @@ -22,7 +22,7 @@ private: static cmDynamicLoaderCache* Instance; }; -cmDynamicLoaderCache* cmDynamicLoaderCache::Instance = CM_NULLPTR; +cmDynamicLoaderCache* cmDynamicLoaderCache::Instance = nullptr; cmDynamicLoaderCache::~cmDynamicLoaderCache() { @@ -65,13 +65,11 @@ bool cmDynamicLoaderCache::FlushCache(const char* path) void cmDynamicLoaderCache::FlushCache() { - for (std::map::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..61d3b468b 100644 --- a/Source/cmDynamicLoader.h +++ b/Source/cmDynamicLoader.h @@ -8,7 +8,7 @@ #ifndef cmDynamicLoader_h #define cmDynamicLoader_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmsys/DynamicLoader.hxx" // IWYU pragma: export diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index fc97bf3b3..76374b2f5 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -2,10 +2,10 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmELF.h" -#include "cm_auto_ptr.hxx" #include "cm_kwiml.h" #include "cmsys/FStream.hxx" #include +#include // IWYU pragma: keep #include #include #include @@ -108,7 +108,7 @@ public: }; // Construct and take ownership of the file stream object. - cmELFInternal(cmELF* external, CM_AUTO_PTR& fin, + cmELFInternal(cmELF* external, std::unique_ptr& fin, ByteOrderType order) : External(external) , Stream(*fin.release()) @@ -231,27 +231,27 @@ public: typedef typename Types::tagtype tagtype; // Construct with a stream and byte swap indicator. - cmELFInternalImpl(cmELF* external, CM_AUTO_PTR& fin, + cmELFInternalImpl(cmELF* external, std::unique_ptr& 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(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 EncodeDynamicEntries(const cmELF::DynamicEntryList&) - CM_OVERRIDE; + cmELF::DynamicEntryList GetDynamicEntries() override; + std::vector 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 +424,8 @@ private: }; template -cmELFInternalImpl::cmELFInternalImpl(cmELF* external, - CM_AUTO_PTR& fin, - ByteOrderType order) +cmELFInternalImpl::cmELFInternalImpl( + cmELF* external, std::unique_ptr& fin, ByteOrderType order) : cmELFInternal(external, fin, order) { // Read the main header. @@ -547,10 +546,7 @@ cmELF::DynamicEntryList cmELFInternalImpl::GetDynamicEntries() // Copy into public array result.reserve(this->DynamicSectionEntries.size()); - for (typename std::vector::iterator di = - this->DynamicSectionEntries.begin(); - di != this->DynamicSectionEntries.end(); ++di) { - ELF_Dyn& dyn = *di; + for (ELF_Dyn& dyn : this->DynamicSectionEntries) { result.push_back( std::pair(dyn.d_tag, dyn.d_un.d_val)); } @@ -565,12 +561,11 @@ std::vector cmELFInternalImpl::EncodeDynamicEntries( std::vector 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(it->first); - dyn.d_un.d_val = static_cast(it->second); + dyn.d_tag = static_cast(entry.first); + dyn.d_un.d_val = static_cast(entry.second); if (this->NeedSwap) { ByteSwap(dyn); @@ -594,7 +589,7 @@ cmELF::StringEntry const* cmELFInternalImpl::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 +600,14 @@ cmELF::StringEntry const* cmELFInternalImpl::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 +622,7 @@ cmELF::StringEntry const* cmELFInternalImpl::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 +651,7 @@ cmELF::StringEntry const* cmELFInternalImpl::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 +662,7 @@ cmELF::StringEntry const* cmELFInternalImpl::GetDynamicSectionString( return &se; } } - return CM_NULLPTR; + return nullptr; } //============================================================================ @@ -683,10 +678,10 @@ const long cmELF::TagMipsRldMapRel = 0; #endif cmELF::cmELF(const char* fname) - : Internal(CM_NULLPTR) + : Internal(nullptr) { // Try to open the file. - CM_AUTO_PTR fin(new cmsys::ifstream(fname)); + std::unique_ptr fin(new cmsys::ifstream(fname)); // Quit now if the file could not be opened. if (!fin.get() || !*fin) { @@ -811,7 +806,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 +816,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 +826,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..8c1734888 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 #include @@ -64,7 +64,7 @@ public: }; /** Represent entire dynamic section header */ - typedef std::vector > DynamicEntryList; + typedef std::vector> 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 const& args, this->SetError("called with incorrect number of arguments"); return false; } - for (std::vector::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 #include @@ -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 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 #include @@ -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 const&, - cmExecutionStatus&) CM_OVERRIDE; + cmExecutionStatus&) override; }; #endif diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx index fcc3c45c6..88e085d5d 100644 --- a/Source/cmExecProgramCommand.cxx +++ b/Source/cmExecProgramCommand.cxx @@ -26,8 +26,8 @@ bool cmExecProgramCommand::InitialPass(std::vector 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 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 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++; } @@ -86,7 +86,7 @@ bool cmExecProgramCommand::InitialPass(std::vector const& args, args[1].c_str(), verbose); } else { result = cmExecProgramCommand::RunCommand(command.c_str(), output, retVal, - CM_NULLPTR, verbose); + nullptr, verbose); } if (!result) { retVal = -1; @@ -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, nullptr }; cmsysProcess_SetCommand(cp, cmd); #endif @@ -217,7 +217,7 @@ 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), p)) { if (p == cmsysProcess_Pipe_STDOUT || p == cmsysProcess_Pipe_STDERR) { if (verbose) { processOutput.DecodeText(data, length, strdata); @@ -235,7 +235,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output, } // 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. diff --git a/Source/cmExecProgramCommand.h b/Source/cmExecProgramCommand.h index 6463c4db5..dc5da740d 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 #include @@ -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 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, + const char* directory = nullptr, bool verbose = true, Encoding encoding = cmProcessOutput::Auto); }; diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 8c10dbe29..39e774e83 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -7,6 +7,7 @@ #include #include +#include "cmAlgorithms.h" #include "cmMakefile.h" #include "cmProcessOutput.h" #include "cmSystemTools.h" @@ -15,7 +16,7 @@ class cmExecutionStatus; static bool cmExecuteProcessCommandIsWhitespace(char c) { - return (isspace((int)c) || c == '\n' || c == '\r'); + return (isspace(static_cast(c)) || c == '\n' || c == '\r'); } void cmExecuteProcessCommandFixText(std::vector& output, @@ -31,7 +32,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, this->SetError("called with incorrect number of arguments"); return false; } - std::vector > cmds; + std::vector> cmds; std::string arguments; bool doing_command = false; size_t command_index = 0; @@ -46,6 +47,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, std::string output_variable; std::string error_variable; std::string result_variable; + std::string results_variable; std::string working_directory; cmProcessOutput::Encoding encoding = cmProcessOutput::None; for (size_t i = 0; i < args.size(); ++i) { @@ -77,6 +79,14 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, this->SetError(" called with no value for RESULT_VARIABLE."); return false; } + } else if (args[i] == "RESULTS_VARIABLE") { + doing_command = false; + if (++i < args.size()) { + results_variable = args[i]; + } else { + this->SetError(" called with no value for RESULTS_VARIABLE."); + return false; + } } else if (args[i] == "WORKING_DIRECTORY") { doing_command = false; if (++i < args.size()) { @@ -160,13 +170,13 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, this->SetError(" called with no COMMAND argument."); return false; } - for (unsigned int i = 0; i < cmds.size(); ++i) { - if (cmds[i].empty()) { + for (auto& cmd : cmds) { + 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); + cmd.push_back(nullptr); } // Parse the timeout string. @@ -182,8 +192,8 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, cmsysProcess* cp = cmsysProcess_New(); // Set the command sequence. - for (unsigned int i = 0; i < cmds.size(); ++i) { - cmsysProcess_AddCommand(cp, &*cmds[i].begin()); + for (auto const& cmd : cmds) { + cmsysProcess_AddCommand(cp, &*cmd.begin()); } // Set the process working directory. @@ -234,7 +244,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, 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), p)) { // Put the output in the right place. if (p == cmsysProcess_Pipe_STDOUT && !output_quiet) { if (output_variable.empty()) { @@ -266,7 +276,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, } // 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); @@ -287,7 +297,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, 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); } break; @@ -305,6 +315,47 @@ bool cmExecuteProcessCommand::InitialPass(std::vector const& args, break; } } + // Store the result of running the processes. + if (!results_variable.empty()) { + switch (cmsysProcess_GetState(cp)) { + case cmsysProcess_State_Exited: { + std::vector res; + for (size_t i = 0; i < cmds.size(); ++i) { + switch (cmsysProcess_GetStateByIndex(cp, static_cast(i))) { + case kwsysProcess_StateByIndex_Exited: { + int exitCode = + cmsysProcess_GetExitValueByIndex(cp, static_cast(i)); + char buf[16]; + sprintf(buf, "%d", exitCode); + res.push_back(buf); + } break; + case kwsysProcess_StateByIndex_Exception: + res.push_back(cmsysProcess_GetExceptionStringByIndex( + cp, static_cast(i))); + break; + case kwsysProcess_StateByIndex_Error: + default: + res.push_back("Error getting the child return code"); + break; + } + } + this->Makefile->AddDefinition(results_variable, + cmJoin(res, ";").c_str()); + } break; + case cmsysProcess_State_Exception: + this->Makefile->AddDefinition(results_variable, + cmsysProcess_GetExceptionString(cp)); + break; + case cmsysProcess_State_Error: + this->Makefile->AddDefinition(results_variable, + cmsysProcess_GetErrorString(cp)); + break; + case cmsysProcess_State_Expired: + this->Makefile->AddDefinition(results_variable, + "Process terminated due to timeout"); + break; + } + } // Delete the process instance. cmsysProcess_Delete(cp); 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmExportBuildAndroidMKGenerator.cxx b/Source/cmExportBuildAndroidMKGenerator.cxx index b443fb0b4..5e2cd535d 100644 --- a/Source/cmExportBuildAndroidMKGenerator.cxx +++ b/Source/cmExportBuildAndroidMKGenerator.cxx @@ -3,7 +3,7 @@ #include "cmExportBuildAndroidMKGenerator.h" #include -#include +#include // IWYU pragma: keep #include #include @@ -16,13 +16,12 @@ #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( @@ -98,43 +97,41 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties( } 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") { + os << (property.second) << "\n"; + } else if (property.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 libraries; - cmSystemTools::ExpandListArgument(pi->second, libraries); + cmSystemTools::ExpandListArgument(property.second, libraries); std::string staticLibs; std::string sharedLibs; std::string ldlibs; - for (std::vector::iterator i = libraries.begin(); - i != libraries.end(); ++i) { + for (std::string const& lib : libraries) { cmGeneratorTarget* gt = - target->GetLocalGenerator()->FindGeneratorTargetToUse(*i); + target->GetLocalGenerator()->FindGeneratorTargetToUse(lib); 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 cge = ge.Parse(*i); + std::unique_ptr cge = ge.Parse(lib); 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 @@ -157,20 +154,19 @@ 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 includeList; cmSystemTools::ExpandListArgument(includes, includeList); os << "LOCAL_EXPORT_C_INCLUDES := "; std::string end; - for (std::vector::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 { - os << "# " << pi->first << " " << (pi->second) << "\n"; + os << "# " << property.first << " " << (property.second) << "\n"; } } } diff --git a/Source/cmExportBuildAndroidMKGenerator.h b/Source/cmExportBuildAndroidMKGenerator.h index d028ef48d..c80839bd4 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 #include @@ -42,25 +42,24 @@ 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; + const std::string& config = "") override; + void GenerateImportFooterCode(std::ostream& os) override; void GenerateImportTargetCode(std::ostream& os, - const cmGeneratorTarget* target) CM_OVERRIDE; + const cmGeneratorTarget* target) 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& missingTargets) CM_OVERRIDE; + std::ostream& os, const std::vector& 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..bb1dda329 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -26,8 +26,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 +45,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) std::string sep; std::vector targets; this->GetTargets(targets); - for (std::vector::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) { @@ -71,10 +70,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) std::vector missingTargets; // Create all the imported targets. - for (std::vector::const_iterator tei = - this->Exports.begin(); - tei != this->Exports.end(); ++tei) { - cmGeneratorTarget* gte = *tei; + for (cmGeneratorTarget* gte : this->Exports) { this->GenerateImportTargetCode(os, gte); gte->Target->AppendBuildInterfaceIncludes(); @@ -115,10 +111,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) } // Generate import file content for each configuration. - for (std::vector::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,11 +124,8 @@ void cmExportBuildFileGenerator::GenerateImportTargetsConfig( std::ostream& os, const std::string& config, std::string const& suffix, std::vector& missingTargets) { - for (std::vector::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) { @@ -184,10 +175,8 @@ void cmExportBuildFileGenerator::SetImportLocationProperty( target->GetObjectSources(objectSources, config); std::string const obj_dir = target->GetObjectDirectory(config); std::vector objects; - for (std::vector::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); } @@ -233,7 +222,7 @@ void cmExportBuildFileGenerator::HandleMissingTarget( dependee->GetLocalGenerator()->GetGlobalGenerator(); std::vector namespaces = this->FindNamespaces(gg, name); - int targetOccurrences = (int)namespaces.size(); + int targetOccurrences = static_cast(namespaces.size()); if (targetOccurrences == 1) { std::string missingTarget = namespaces[0]; @@ -256,10 +245,8 @@ void cmExportBuildFileGenerator::GetTargets( std::vector& targets) const { if (this->ExportSet) { - for (std::vector::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 +261,8 @@ std::vector cmExportBuildFileGenerator::FindNamespaces( std::map& exportSets = gg->GetBuildExportSets(); - for (std::map::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 targets; exportSet->GetTargets(targets); if (std::find(targets.begin(), targets.end(), name) != targets.end()) { diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h index 0556983ac..6457a7787 100644 --- a/Source/cmExportBuildFileGenerator.h +++ b/Source/cmExportBuildFileGenerator.h @@ -3,7 +3,7 @@ #ifndef cmExportBuildFileGenerator_h #define cmExportBuildFileGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmExportFileGenerator.h" @@ -49,14 +49,14 @@ 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& missingTargets) CM_OVERRIDE; + std::vector& missingTargets) override; void HandleMissingTarget(std::string& link_libs, std::vector& missingTargets, cmGeneratorTarget* depender, - cmGeneratorTarget* dependee) CM_OVERRIDE; + cmGeneratorTarget* dependee) override; void ComplainAboutMissingTarget(cmGeneratorTarget* depender, cmGeneratorTarget* dependee, @@ -69,7 +69,7 @@ protected: ImportPropertyMap& properties); std::string InstallNameDir(cmGeneratorTarget* target, - const std::string& config) CM_OVERRIDE; + const std::string& config) override; std::vector FindNamespaces(cmGlobalGenerator* gg, const std::string& name); diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index 38cd511ea..991312983 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -35,7 +35,7 @@ cmExportCommand::cmExportCommand() , ExportOld(&Helper, "EXPORT_LINK_INTERFACE_LIBRARIES", &ArgumentGroup) , AndroidMKFile(&Helper, "ANDROID_MK") { - this->ExportSet = CM_NULLPTR; + this->ExportSet = nullptr; } // cmExportCommand @@ -51,10 +51,10 @@ bool cmExportCommand::InitialPass(std::vector const& args, return this->HandlePackage(args); } if (args[0] == "EXPORT") { - this->ExportSetName.Follows(CM_NULLPTR); + this->ExportSetName.Follows(nullptr); this->ArgumentGroup.Follows(&this->ExportSetName); } else { - this->Targets.Follows(CM_NULLPTR); + this->Targets.Follows(nullptr); this->ArgumentGroup.Follows(&this->Targets); } @@ -136,42 +136,40 @@ bool cmExportCommand::InitialPass(std::vector const& args, } this->ExportSet = setMap[setName]; } else if (this->Targets.WasFound()) { - for (std::vector::const_iterator currentTarget = - this->Targets.GetVector().begin(); - currentTarget != this->Targets.GetVector().end(); ++currentTarget) { - if (this->Makefile->IsAlias(*currentTarget)) { + for (std::string const& currentTarget : this->Targets.GetVector()) { + 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 (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 + e << "given OBJECT library \"" << currentTarget << "\" which may not be exported" << reason << "."; this->SetError(e.str()); return false; } } 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 (cmExportBuildFileGenerator* ebfg = @@ -186,7 +184,7 @@ bool cmExportCommand::InitialPass(std::vector const& args, } // Setup export file generation. - cmExportBuildFileGenerator* ebfg = CM_NULLPTR; + cmExportBuildFileGenerator* ebfg = nullptr; if (android) { ebfg = new cmExportBuildAndroidMKGenerator; } else { @@ -209,10 +207,8 @@ bool cmExportCommand::InitialPass(std::vector const& args, if (configurationTypes.empty()) { configurationTypes.push_back(""); } - for (std::vector::const_iterator ci = - configurationTypes.begin(); - ci != configurationTypes.end(); ++ci) { - ebfg->AddConfiguration(*ci); + for (std::string const& ct : configurationTypes) { + ebfg->AddConfiguration(ct); } if (this->ExportSet) { gg->AddBuildExportExportSet(ebfg); diff --git a/Source/cmExportCommand.h b/Source/cmExportCommand.h index c47bc42b9..a5c6751bf 100644 --- a/Source/cmExportCommand.h +++ b/Source/cmExportCommand.h @@ -3,7 +3,7 @@ #ifndef cmExportCommand_h #define cmExportCommand_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -27,14 +27,14 @@ public: /** * 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: cmCommandArgumentsHelper Helper; diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 972f4b9d1..7f0cb9729 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -17,9 +17,9 @@ #include "cmTargetExport.h" #include "cmake.h" -#include "cm_auto_ptr.hxx" #include "cmsys/FStream.hxx" #include +#include // IWYU pragma: keep #include #include #include @@ -65,18 +65,17 @@ const char* cmExportFileGenerator::GetMainExportFileName() const bool cmExportFileGenerator::GenerateImportFile() { // Open the output file to generate it. - CM_AUTO_PTR foutPtr; + std::unique_ptr foutPtr; if (this->AppendMode) { // Open for append. - CM_AUTO_PTR ap( - new cmsys::ofstream(this->MainImportFile.c_str(), std::ios::app)); - foutPtr = ap; + foutPtr = cm::make_unique(this->MainImportFile.c_str(), + std::ios::app); } else { // Generate atomically and with copy-if-different. - CM_AUTO_PTR ap( + std::unique_ptr ap( new cmGeneratedFileStream(this->MainImportFile.c_str(), true)); ap->SetCopyIfDifferent(true); - foutPtr = ap; + foutPtr = std::move(ap); } if (!foutPtr.get() || !*foutPtr) { std::string se = cmSystemTools::GetLastSystemError(); @@ -137,7 +136,7 @@ void cmExportFileGenerator::PopulateInterfaceProperty( if (input) { if (!*input) { // Set to empty - properties[outputName] = ""; + properties[outputName].clear(); return; } @@ -206,9 +205,8 @@ static bool checkInterfaceDirs(const std::string& prepro, bool hadFatalError = false; - for (std::vector::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; } @@ -233,20 +231,20 @@ static bool checkInterfaceDirs(const std::string& prepro, hadFatalError = true; } } - if (cmHasLiteralPrefix(li->c_str(), "${_IMPORT_PREFIX}")) { + if (cmHasLiteralPrefix(li.c_str(), "${_IMPORT_PREFIX}")) { continue; } - if (!cmSystemTools::FileIsFullPath(li->c_str())) { + if (!cmSystemTools::FileIsFullPath(li.c_str())) { /* 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.c_str(), topBinaryDir); + bool inSource = isSubDirectory(li.c_str(), topSourceDir); + if (isSubDirectory(li.c_str(), installDir)) { // The include directory is inside the install tree. If the // install tree is not inside the source tree or build tree then // fall through to the checks below that the include directory is not @@ -261,7 +259,7 @@ 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 " @@ -293,7 +291,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 +300,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 +312,16 @@ static void prefixItems(std::string& exportDirs) { std::vector entries; cmGeneratorExpression::Split(exportDirs, entries); - exportDirs = ""; + exportDirs.clear(); const char* sep = ""; - for (std::vector::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.c_str()) && + e.find("${_IMPORT_PREFIX}") == std::string::npos) { exportDirs += "${_IMPORT_PREFIX}/"; } - exportDirs += *ei; + exportDirs += e; } } @@ -343,7 +340,7 @@ void cmExportFileGenerator::PopulateSourcesInterface( } if (!*input) { - properties[propName] = ""; + properties[propName].clear(); return; } @@ -374,7 +371,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( std::string dirs = cmGeneratorExpression::Preprocess( tei->InterfaceIncludeDirectories, preprocessRule, true); this->ReplaceInstallPrefix(dirs); - CM_AUTO_PTR cge = ge.Parse(dirs); + std::unique_ptr cge = ge.Parse(dirs); std::string exportDirs = cge->Evaluate(target->GetLocalGenerator(), "", false, target); @@ -396,7 +393,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( } if ((input && !*input) && exportDirs.empty()) { // Set to empty - properties[propName] = ""; + properties[propName].clear(); return; } @@ -461,18 +458,17 @@ void getCompatibleInterfaceProperties(cmGeneratorTarget* target, 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 +500,13 @@ void cmExportFileGenerator::PopulateCompatibleInterfaceProperties( std::vector configNames; gtarget->Target->GetMakefile()->GetConfigurations(configNames); - for (std::vector::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::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 +518,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"; } @@ -571,15 +564,14 @@ void cmExportFileGenerator::ResolveTargetsInGeneratorExpressions( cmGeneratorExpression::Split(input, parts); std::string sep; - input = ""; - for (std::vector::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 = ";"; } } @@ -720,7 +712,7 @@ void cmExportFileGenerator::SetImportLinkInterface( } if (!*propContent) { - properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = ""; + properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix].clear(); return; } @@ -797,13 +789,12 @@ void cmExportFileGenerator::SetImportLinkProperty( // Construct the property value. std::string link_entries; const char* sep = ""; - for (typename std::vector::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 = l; this->AddTargetNamespace(temp, target, missingTargets); link_entries += temp; } @@ -988,10 +979,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 +1005,9 @@ void cmExportFileGenerator::GenerateMissingTargetsCheckCode( "foreach(_target "; /* clang-format on */ std::set 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 +1084,8 @@ void cmExportFileGenerator::GenerateImportedFileChecksCode( "list(APPEND _IMPORT_CHECK_FILES_FOR_" << targetName << " "; - for (std::set::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) << " "; } diff --git a/Source/cmExportInstallAndroidMKGenerator.cxx b/Source/cmExportInstallAndroidMKGenerator.cxx index 9a1c647d3..fe565e623 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::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; } diff --git a/Source/cmExportInstallAndroidMKGenerator.h b/Source/cmExportInstallAndroidMKGenerator.h index ebef78365..316598290 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 #include @@ -36,37 +36,36 @@ 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; + const std::string& config = "") override; + void GenerateImportFooterCode(std::ostream& os) override; void GenerateImportTargetCode(std::ostream& os, - const cmGeneratorTarget* target) CM_OVERRIDE; + const cmGeneratorTarget* target) 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& missingTargets) CM_OVERRIDE; + std::ostream& os, const std::vector& 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& importedLocations) CM_OVERRIDE; + const std::set& importedLocations) override; bool GenerateImportFileConfig(const std::string& config, - std::vector&) CM_OVERRIDE; + std::vector&) override; }; #endif diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index 664a34276..9b65e9e5c 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -4,7 +4,6 @@ #include "cmAlgorithms.h" #include "cmExportSet.h" -#include "cmExportSetMap.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" @@ -22,6 +21,8 @@ #include #include +class cmExportSetMap; + cmExportInstallFileGenerator::cmExportInstallFileGenerator( cmInstallExportGenerator* iegen) : IEGen(iegen) @@ -42,14 +43,10 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) { std::string expectedTargets; std::string sep; - for (std::vector::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 { @@ -76,9 +73,8 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) bool require3_1_0 = false; bool requiresConfigFiles = false; // Create all the imported targets. - for (std::vector::const_iterator tei = allTargets.begin(); - tei != allTargets.end(); ++tei) { - cmGeneratorTarget* gt = (*tei)->Target; + for (cmTargetExport* te : allTargets) { + cmGeneratorTarget* gt = te->Target; requiresConfigFiles = requiresConfigFiles || gt->GetType() != cmStateEnums::INTERFACE_LIBRARY; @@ -88,10 +84,8 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) 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, @@ -154,10 +148,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::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; } } @@ -314,11 +306,8 @@ void cmExportInstallFileGenerator::GenerateImportTargetsConfig( std::vector& missingTargets) { // Add each target in the set to the export. - for (std::vector::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; } @@ -409,9 +398,8 @@ void cmExportInstallFileGenerator::SetImportLocationProperty( // IMPORTED_OBJECTS as a list of object files std::vector objects; itgen->GetInstallObjectNames(config, objects); - for (std::vector::iterator i = objects.begin(); - i != objects.end(); ++i) { - *i = value + *i; + for (std::string& obj : objects) { + obj = value + obj; } // Store the property. @@ -445,7 +433,7 @@ void cmExportInstallFileGenerator::HandleMissingTarget( const std::string name = dependee->GetName(); cmGlobalGenerator* gg = dependee->GetLocalGenerator()->GetGlobalGenerator(); std::vector namespaces = this->FindNamespaces(gg, name); - int targetOccurrences = (int)namespaces.size(); + int targetOccurrences = static_cast(namespaces.size()); if (targetOccurrences == 1) { std::string missingTarget = namespaces[0]; @@ -465,15 +453,14 @@ std::vector cmExportInstallFileGenerator::FindNamespaces( std::vector 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 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 +469,8 @@ std::vector cmExportInstallFileGenerator::FindNamespaces( if (containsTarget) { std::vector 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()); } } } diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h index 8fa9b7f88..cda8433a2 100644 --- a/Source/cmExportInstallFileGenerator.h +++ b/Source/cmExportInstallFileGenerator.h @@ -3,7 +3,7 @@ #ifndef cmExportInstallFileGenerator_h #define cmExportInstallFileGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmExportFileGenerator.h" @@ -53,16 +53,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& missingTargets) CM_OVERRIDE; + std::vector& missingTargets) override; void HandleMissingTarget(std::string& link_libs, std::vector& 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 +91,7 @@ protected: std::set& 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..50f8cb014 100644 --- a/Source/cmExportLibraryDependenciesCommand.cxx +++ b/Source/cmExportLibraryDependenciesCommand.cxx @@ -4,8 +4,10 @@ #include "cmsys/FStream.hxx" #include +#include // IWYU pragma: keep #include +#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,16 +48,15 @@ void cmExportLibraryDependenciesCommand::FinalPass() void cmExportLibraryDependenciesCommand::ConstFinalPass() const { // Use copy-if-different if not appending. - CM_AUTO_PTR foutPtr; + std::unique_ptr foutPtr; if (this->Append) { - CM_AUTO_PTR ap( - new cmsys::ofstream(this->Filename.c_str(), std::ios::app)); - foutPtr = ap; + foutPtr = + cm::make_unique(this->Filename.c_str(), std::ios::app); } else { - CM_AUTO_PTR ap( + std::unique_ptr ap( new cmGeneratedFileStream(this->Filename.c_str(), true)); ap->SetCopyIfDifferent(true); - foutPtr = ap; + foutPtr = std::move(ap); } std::ostream& fout = *foutPtr; @@ -75,12 +74,11 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const std::map libDepsOld; std::map libDepsNew; std::map libTypes; - for (std::vector::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) { + const cmTargets& tgts = local->GetTargets(); + for (auto const& tgt : tgts) { // 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::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::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::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..bf5e9bc54 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 #include @@ -15,15 +15,15 @@ class cmExecutionStatus; class cmExportLibraryDependenciesCommand : public cmCommand { public: - cmCommand* Clone() CM_OVERRIDE + cmCommand* Clone() override { return new cmExportLibraryDependenciesCommand; } bool InitialPass(std::vector 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; 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::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/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx index cd0a7e69a..1fb9cf818 100644 --- a/Source/cmExportTryCompileFileGenerator.cxx +++ b/Source/cmExportTryCompileFileGenerator.cxx @@ -11,9 +11,9 @@ #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cm_auto_ptr.hxx" #include +#include // IWYU pragma: keep #include cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator( @@ -62,10 +62,10 @@ std::string cmExportTryCompileFileGenerator::FindTargets( cmGeneratorExpression ge; - cmGeneratorExpressionDAGChecker dagChecker(tgt->GetName(), propName, - CM_NULLPTR, CM_NULLPTR); + cmGeneratorExpressionDAGChecker dagChecker(tgt->GetName(), propName, nullptr, + nullptr); - CM_AUTO_PTR cge = ge.Parse(prop); + std::unique_ptr cge = ge.Parse(prop); cmTarget dummyHead("try_compile_dummy_exe", cmStateEnums::EXECUTABLE, cmTarget::VisibilityNormal, tgt->Target->GetMakefile()); @@ -77,11 +77,9 @@ std::string cmExportTryCompileFileGenerator::FindTargets( const std::set& allTargets = cge->GetAllTargetsSeen(); - for (std::set::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 +90,20 @@ void cmExportTryCompileFileGenerator::PopulateProperties( std::set& emitted) { std::vector props = target->GetPropertyKeys(); - for (std::vector::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, emitted); std::vector depends; cmSystemTools::ExpandListArgument(evalResult, depends); - for (std::vector::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..70c385728 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" @@ -27,15 +27,15 @@ public: 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&) CM_OVERRIDE + std::vector&) override { } void HandleMissingTarget(std::string&, std::vector&, - cmGeneratorTarget*, cmGeneratorTarget*) CM_OVERRIDE + cmGeneratorTarget*, cmGeneratorTarget*) override { } @@ -44,7 +44,7 @@ protected: std::set& 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, diff --git a/Source/cmExprParserHelper.cxx b/Source/cmExprParserHelper.cxx index c3f026a4e..fe7159a8d 100644 --- a/Source/cmExprParserHelper.cxx +++ b/Source/cmExprParserHelper.cxx @@ -2,8 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmExprParserHelper.h" -#include "cmConfigure.h" - #include "cmExprLexer.h" #include @@ -14,7 +12,7 @@ int cmExpr_yyparse(yyscan_t yyscanner); cmExprParserHelper::cmExprParserHelper() { this->FileLine = -1; - this->FileName = CM_NULLPTR; + this->FileName = nullptr; } cmExprParserHelper::~cmExprParserHelper() diff --git a/Source/cmExternalMakefileProjectGenerator.h b/Source/cmExternalMakefileProjectGenerator.h index 6b8903790..a1734eef2 100644 --- a/Source/cmExternalMakefileProjectGenerator.h +++ b/Source/cmExternalMakefileProjectGenerator.h @@ -99,7 +99,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..9c9b75b17 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -62,11 +63,9 @@ cmExtraCodeBlocksGenerator::GetFactory() void cmExtraCodeBlocksGenerator::Generate() { // for each sub project in the project create a codeblocks project - for (std::map >::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 +94,7 @@ struct Tree { std::string path; // only one component of the path std::vector folders; - std::vector files; + std::set files; void InsertPath(const std::vector& splitted, std::vector::size_type start, const std::string& fileName); @@ -112,18 +111,17 @@ void Tree::InsertPath(const std::vector& splitted, const std::string& fileName) { if (start == splitted.size()) { - files.push_back(fileName); + files.insert(fileName); return; } - for (std::vector::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 +134,7 @@ void Tree::InsertPath(const std::vector& splitted, return; } // last part of splitted - newFolder.files.push_back(fileName); + newFolder.files.insert(fileName); folders.push_back(newFolder); } @@ -144,9 +142,8 @@ void Tree::BuildVirtualFolder(cmXMLWriter& xml) const { xml.StartElement("Option"); std::string virtualFolders = "CMake Files\\;"; - for (std::vector::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 +153,16 @@ void Tree::BuildVirtualFolderImpl(std::string& virtualFolders, const std::string& prefix) const { virtualFolders += "CMake Files\\" + prefix + path + "\\;"; - for (std::vector::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::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 +170,8 @@ void Tree::BuildUnit(cmXMLWriter& xml, const std::string& fsPath) const xml.EndElement(); } - for (std::vector::const_iterator it = folders.begin(); - it != folders.end(); ++it) { - it->BuildUnitImpl(xml, "", fsPath); + for (Tree const& folder : folders) { + folder.BuildUnitImpl(xml, "", fsPath); } } @@ -185,10 +179,9 @@ void Tree::BuildUnitImpl(cmXMLWriter& xml, const std::string& virtualFolderPath, const std::string& fsPath) const { - for (std::vector::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 +190,9 @@ void Tree::BuildUnitImpl(cmXMLWriter& xml, xml.EndElement(); } - for (std::vector::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 + "/"); } } @@ -216,29 +208,24 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( Tree tree; // build tree of virtual folders - for (std::map >::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 listFiles; - for (std::vector::const_iterator jt = - it->second.begin(); - jt != it->second.end(); ++jt) { + for (cmLocalGenerator* lg : it.second) { const std::vector& files = - (*jt)->GetMakefile()->GetListFiles(); + lg->GetMakefile()->GetListFiles(); listFiles.insert(listFiles.end(), files.begin(), files.end()); } // Convert - for (std::vector::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.c_str()); std::vector splitted; cmSystemTools::SplitPath(relative, splitted, false); // Split filename from path @@ -248,7 +235,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); } @@ -289,24 +283,22 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( xml.StartElement("Build"); - this->AppendTarget(xml, "all", CM_NULLPTR, make.c_str(), lgs[0], + this->AppendTarget(xml, "all", nullptr, make.c_str(), lgs[0], compiler.c_str(), makeArgs); // add all executable and library targets and some of the GLOBAL // and UTILITY targets - for (std::vector::const_iterator lg = lgs.begin(); - lg != lgs.end(); lg++) { - std::vector targets = (*lg)->GetGeneratorTargets(); - for (std::vector::iterator ti = targets.begin(); - ti != targets.end(); ti++) { - std::string targetName = (*ti)->GetName(); - switch ((*ti)->GetType()) { + for (cmLocalGenerator* lg : lgs) { + const std::vector& 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, + if (strcmp(lg->GetCurrentBinaryDirectory(), + lg->GetBinaryDirectory()) == 0) { + this->AppendTarget(xml, targetName, nullptr, make.c_str(), lg, compiler.c_str(), makeArgs); } } break; @@ -322,7 +314,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( break; } - this->AppendTarget(xml, targetName, CM_NULLPTR, make.c_str(), *lg, + this->AppendTarget(xml, targetName, nullptr, make.c_str(), lg, compiler.c_str(), makeArgs); break; case cmStateEnums::EXECUTABLE: @@ -330,12 +322,12 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::MODULE_LIBRARY: case cmStateEnums::OBJECT_LIBRARY: { - cmGeneratorTarget* gt = *ti; - this->AppendTarget(xml, targetName, gt, make.c_str(), *lg, + cmGeneratorTarget* gt = target; + this->AppendTarget(xml, targetName, gt, make.c_str(), lg, compiler.c_str(), makeArgs); std::string fastTarget = targetName; fastTarget += "/fast"; - this->AppendTarget(xml, fastTarget, gt, make.c_str(), *lg, + this->AppendTarget(xml, fastTarget, gt, make.c_str(), lg, compiler.c_str(), makeArgs); } break; default: @@ -356,13 +348,11 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( std::vector const& srcExts = this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions(); - for (std::vector::const_iterator lg = lgs.begin(); - lg != lgs.end(); lg++) { - cmMakefile* makefile = (*lg)->GetMakefile(); - std::vector targets = (*lg)->GetGeneratorTargets(); - for (std::vector::iterator ti = targets.begin(); - ti != targets.end(); ti++) { - switch ((*ti)->GetType()) { + for (cmLocalGenerator* lg : lgs) { + cmMakefile* makefile = lg->GetMakefile(); + const std::vector& targets = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { + switch (target->GetType()) { case cmStateEnums::EXECUTABLE: case cmStateEnums::STATIC_LIBRARY: case cmStateEnums::SHARED_LIBRARY: @@ -371,41 +361,51 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( case cmStateEnums::UTILITY: // can have sources since 2.6.3 { std::vector sources; - cmGeneratorTarget* gt = *ti; + cmGeneratorTarget* gt = target; gt->GetSourceFiles(sources, makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); - for (std::vector::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->GetPropertyAsBool("GENERATED")) { continue; } // check whether it is a C/C++ implementation file bool isCFile = false; - std::string lang = (*si)->GetLanguage(); + std::string lang = s->GetLanguage(); if (lang == "C" || lang == "CXX") { - std::string const& srcext = (*si)->GetExtension(); - for (std::vector::const_iterator ext = - srcExts.begin(); - ext != srcExts.end(); ++ext) { - if (srcext == *ext) { + std::string const& srcext = s->GetExtension(); + for (std::string const& ext : srcExts) { + if (srcext == ext) { isCFile = true; break; } } } - 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.c_str()); + // 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 @@ -424,19 +424,16 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( // file exists. If it does, it is inserted into the map of files. // A very similar version of that code exists also in the kdevelop // project generator. - for (std::vector::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::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; @@ -450,19 +447,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_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(); } @@ -515,7 +509,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 +517,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,10 +566,9 @@ void cmExtraCodeBlocksGenerator::AppendTarget( target->GetCompileDefinitions(cdefs, buildType, "C"); // Expand the list. - for (std::vector::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(); } diff --git a/Source/cmExtraCodeBlocksGenerator.h b/Source/cmExtraCodeBlocksGenerator.h index 450a9d02c..be3af2562 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 diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index b478f34fa..5a02d54eb 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -54,26 +54,24 @@ void cmExtraCodeLiteGenerator::Generate() std::string workspaceFileName; std::string workspaceSourcePath; - const std::map >& projectMap = + const std::map>& projectMap = this->GlobalGenerator->GetProjectMap(); // loop projects and locate the root project. // and extract the information for creating the worspace // root makefile - for (std::map >::const_iterator - it = projectMap.begin(); - it != projectMap.end(); ++it) { - const cmMakefile* mf = it->second[0]->GetMakefile(); + for (auto const& it : projectMap) { + const cmMakefile* mf = it.second[0]->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 (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(); workspaceFileName = workspaceOutputDir + "/"; workspaceFileName += workspaceProjectName + ".workspace"; - this->WorkspacePath = it->second[0]->GetCurrentBinaryDirectory(); + this->WorkspacePath = it.second[0]->GetCurrentBinaryDirectory(); ; break; } @@ -101,10 +99,9 @@ void cmExtraCodeLiteGenerator::Generate() xml.Attribute("Name", this->ConfigName); xml.Attribute("Selected", "yes"); - for (std::vector::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,14 +119,11 @@ std::vector cmExtraCodeLiteGenerator::CreateProjectsByTarget( // for each target in the workspace create a codelite project const std::vector& lgs = this->GlobalGenerator->GetLocalGenerators(); - for (std::vector::const_iterator lg(lgs.begin()); - lg != lgs.end(); lg++) { - for (std::vector::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 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 @@ -149,7 +143,7 @@ std::vector cmExtraCodeLiteGenerator::CreateProjectsByTarget( xml->Attribute("Active", "No"); xml->EndElement(); - CreateNewProjectFile(*lt, filename); + CreateNewProjectFile(lt, filename); break; default: break; @@ -165,12 +159,10 @@ std::vector cmExtraCodeLiteGenerator::CreateProjectsByProjectMaps( { std::vector retval; // for each sub project in the workspace create a codelite project - for (std::map >::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 outputDir = it.second[0]->GetCurrentBinaryDirectory(); + std::string projectName = it.second[0]->GetProjectName(); retval.push_back(projectName); std::string filename = outputDir + "/" + projectName + ".project"; @@ -179,7 +171,7 @@ std::vector cmExtraCodeLiteGenerator::CreateProjectsByProjectMaps( filename.c_str()); // create a project file - this->CreateProjectFile(it->second); + this->CreateProjectFile(it.second); xml->StartElement("Project"); xml->Attribute("Name", projectName); xml->Attribute("Path", filename); @@ -235,16 +227,14 @@ std::string cmExtraCodeLiteGenerator::CollectSourceFiles( std::vector sources; gt->GetSourceFiles(sources, makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); - for (std::vector::const_iterator si = sources.begin(); - si != sources.end(); si++) { + for (cmSourceFile* s : sources) { // check whether it is a C/C++ implementation file bool isCFile = false; - std::string lang = (*si)->GetLanguage(); + std::string lang = s->GetLanguage(); if (lang == "C" || lang == "CXX") { - std::string const& srcext = (*si)->GetExtension(); - for (std::vector::const_iterator ext = srcExts.begin(); - ext != srcExts.end(); ++ext) { - if (srcext == *ext) { + std::string const& srcext = s->GetExtension(); + for (std::string const& ext : srcExts) { + if (srcext == ext) { isCFile = true; break; } @@ -253,9 +243,9 @@ std::string cmExtraCodeLiteGenerator::CollectSourceFiles( // then put it accordingly into one of the two containers if (isCFile) { - cFiles[(*si)->GetFullPath()] = *si; + cFiles[s->GetFullPath()] = s; } else { - otherFiles.insert((*si)->GetFullPath()); + otherFiles.insert(s->GetFullPath()); } } } @@ -289,13 +279,11 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile( std::map cFiles; std::set otherFiles; - for (std::vector::const_iterator lg = lgs.begin(); - lg != lgs.end(); lg++) { - cmMakefile* makefile = (*lg)->GetMakefile(); - std::vector targets = (*lg)->GetGeneratorTargets(); - for (std::vector::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& targets = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { + projectType = CollectSourceFiles(makefile, target, cFiles, otherFiles); } } @@ -323,19 +311,16 @@ void cmExtraCodeLiteGenerator::FindMatchingHeaderfiles( // file exists. If it does, it is inserted into the map of files. // A very similar version of that code exists also in the kdevelop // project generator. - for (std::map::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::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::const_iterator headerIt = otherFiles.find(hname); if (headerIt != otherFiles.end()) { @@ -358,10 +343,9 @@ void cmExtraCodeLiteGenerator::CreateFoldersAndFiles( std::vector components; size_t numOfEndEl = 0; - for (std::set::const_iterator it = cFiles.begin(); - it != cFiles.end(); ++it) { + for (std::string const& cFile : cFiles) { std::string frelapath = - cmSystemTools::RelativePath(projectPath.c_str(), it->c_str()); + cmSystemTools::RelativePath(projectPath.c_str(), cFile.c_str()); 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 +407,8 @@ void cmExtraCodeLiteGenerator::CreateFoldersAndFiles( const std::string& projectPath) { std::set s; - for (std::map::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); } diff --git a/Source/cmExtraCodeLiteGenerator.h b/Source/cmExtraCodeLiteGenerator.h index de330988d..029054fdd 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" @@ -60,7 +60,7 @@ public: static cmExternalMakefileProjectGeneratorFactory* GetFactory(); - void Generate() CM_OVERRIDE; + void Generate() override; void CreateProjectFile(const std::vector& lgs); void CreateNewProjectFile(const std::vector& lgs, diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 2a6ce98a7..a200385ee 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -5,7 +5,6 @@ #include "cmsys/RegularExpression.hxx" #include #include -#include #include #include #include @@ -78,16 +77,15 @@ void cmExtraEclipseCDT4Generator::EnableLanguage( std::vector const& languages, cmMakefile* /*unused*/, bool /*optional*/) { - for (std::vector::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"); } } @@ -222,17 +220,17 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out, // 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; } else { @@ -382,18 +380,16 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile() xml.Element("nature", "org.eclipse.cdt.make.core.ScannerConfigNature"); ; - for (std::set::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 extraNatures; cmSystemTools::ExpandListArgument(extraNaturesProp, extraNatures); - for (std::vector::const_iterator nit = extraNatures.begin(); - nit != extraNatures.end(); ++nit) { - xml.Element("nature", *nit); + for (std::string const& n : extraNatures) { + xml.Element("nature", n); } } @@ -435,25 +431,22 @@ void cmExtraEclipseCDT4Generator::WriteGroups( std::vector const& sourceGroups, std::string& linkName, cmXMLWriter& xml) { - for (std::vector::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 const& children = sgIt->GetGroupChildren(); + std::vector const& children = sg.GetGroupChildren(); if (!children.empty()) { this->WriteGroups(children, linkName, xml); } - std::vector sFiles = sgIt->GetSourceFiles(); - for (std::vector::const_iterator fileIt = - sFiles.begin(); - fileIt != sFiles.end(); ++fileIt) { - std::string const& fullPath = (*fileIt)->GetFullPath(); + std::vector sFiles = sg.GetSourceFiles(); + for (cmSourceFile const* file : sFiles) { + std::string const& fullPath = file->GetFullPath(); if (!cmSystemTools::FileIsDirectory(fullPath)) { std::string linkName4 = linkName3; @@ -471,28 +464,24 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml) std::string linkName = "[Targets]"; this->AppendLinkedResource(xml, linkName, "virtual:/virtual", VirtualFolder); - for (std::vector::const_iterator lgIt = - this->GlobalGenerator->GetLocalGenerators().begin(); - lgIt != this->GlobalGenerator->GetLocalGenerators().end(); ++lgIt) { - cmMakefile* makefile = (*lgIt)->GetMakefile(); - const std::vector targets = - (*lgIt)->GetGeneratorTargets(); + for (cmLocalGenerator* lg : this->GlobalGenerator->GetLocalGenerators()) { + cmMakefile* makefile = lg->GetMakefile(); + const std::vector& targets = lg->GetGeneratorTargets(); - for (std::vector::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(); + linkName2 += target->GetName(); this->AppendLinkedResource(xml, linkName2, "virtual:/virtual", VirtualFolder); if (!this->GenerateLinkedResources) { @@ -501,17 +490,16 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml) std::vector sourceGroups = makefile->GetSourceGroups(); // get the files from the source lists then add them to the groups - cmGeneratorTarget* gt = const_cast(*ti); + cmGeneratorTarget* gt = const_cast(target); std::vector files; gt->GetSourceFiles(files, makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); - for (std::vector::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); + sourceGroup->AssignSource(sf); } this->WriteGroups(sourceGroups, linkName2, xml); @@ -536,17 +524,15 @@ void cmExtraEclipseCDT4Generator::CreateLinksToSubprojects( this->AppendLinkedResource(xml, "[Subprojects]", "virtual:/virtual", VirtualFolder); - for (std::map >::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()); + this->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; + linkName += it.first; this->AppendLinkedResource(xml, linkName, this->GetEclipsePath(linkSourceDirectory), LinkToFolder); @@ -560,10 +546,9 @@ void cmExtraEclipseCDT4Generator::AppendIncludeDirectories( cmXMLWriter& xml, const std::vector& includeDirs, std::set& emittedDirs) { - for (std::vector::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 @@ -712,19 +697,17 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const xml.EndElement(); } - for (std::vector::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 // - 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 +721,31 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const // add pre-processor definitions to allow eclipse to gray out sections emmited.clear(); - for (std::vector::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 defs; cmGeneratorExpression::Split(cdefs, defs); - for (std::vector::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 +830,13 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const // include dirs emmited.clear(); - for (std::vector::const_iterator it = - this->GlobalGenerator->GetLocalGenerators().begin(); - it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) { - std::vector targets = (*it)->GetGeneratorTargets(); - for (std::vector::iterator l = targets.begin(); - l != targets.end(); ++l) { + for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) { + const std::vector& targets = + lgen->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { std::vector 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); } } @@ -907,21 +885,18 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const // add all executable and library targets and some of the GLOBAL // and UTILITY targets - for (std::vector::const_iterator it = - this->GlobalGenerator->GetLocalGenerators().begin(); - it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) { - const std::vector targets = - (*it)->GetGeneratorTargets(); - std::string subdir = (*it)->ConvertToRelativePath( - this->HomeOutputDirectory, (*it)->GetCurrentBinaryDirectory()); + for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) { + const std::vector& targets = + lgen->GetGeneratorTargets(); + std::string subdir = lgen->ConvertToRelativePath( + this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory()); if (subdir == ".") { - subdir = ""; + subdir.clear(); } - for (std::vector::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 @@ -949,8 +924,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const case cmStateEnums::MODULE_LIBRARY: case cmStateEnums::OBJECT_LIBRARY: { const char* prefix = - ((*ti)->GetType() == cmStateEnums::EXECUTABLE ? "[exe] " - : "[lib] "); + (target->GetType() == cmStateEnums::EXECUTABLE ? "[exe] " + : "[lib] "); this->AppendTarget(xml, targetName, make, makeArgs, subdir, prefix); std::string fastTarget = targetName; fastTarget += "/fast"; @@ -962,19 +937,19 @@ 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()); 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, "", ""); @@ -996,17 +971,15 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const // insert rules for compiling, preprocessing and assembling individual // files std::vector objectFileTargets; - (*it)->GetIndividualFileTargets(objectFileTargets); - for (std::vector::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[f.length() - 1] == 's') { prefix = "[to asm] "; - } else if ((*fit)[fit->length() - 1] == 'i') { + } else if (f[f.length() - 1] == 'i') { prefix = "[pre] "; } - this->AppendTarget(xml, *fit, make, makeArgs, subdir, prefix); + this->AppendTarget(xml, f, make, makeArgs, subdir, prefix); } } 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 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..79cc6ef52 100644 --- a/Source/cmExtraKateGenerator.cxx +++ b/Source/cmExtraKateGenerator.cxx @@ -112,18 +112,16 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg, // add all executable and library targets and some of the GLOBAL // and UTILITY targets - for (std::vector::const_iterator it = - this->GlobalGenerator->GetLocalGenerators().begin(); - it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) { - const std::vector targets = - (*it)->GetGeneratorTargets(); - std::string currentDir = (*it)->GetCurrentBinaryDirectory(); - bool topLevel = (currentDir == (*it)->GetBinaryDirectory()); - - for (std::vector::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& 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 +132,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 +181,9 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg, // insert rules for compiling, preprocessing and assembling individual // files std::vector objectFileTargets; - (*it)->GetIndividualFileTargets(objectFileTargets); - for (std::vector::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); } } @@ -251,22 +246,18 @@ std::string cmExtraKateGenerator::GenerateFilesString( const std::vector& lgs = this->GlobalGenerator->GetLocalGenerators(); - for (std::vector::const_iterator it = lgs.begin(); - it != lgs.end(); it++) { - cmMakefile* makefile = (*it)->GetMakefile(); + for (cmLocalGenerator* lgen : lgs) { + cmMakefile* makefile = lgen->GetMakefile(); const std::vector& listFiles = makefile->GetListFiles(); - for (std::vector::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& sources = makefile->GetSourceFiles(); - for (std::vector::const_iterator sfIt = sources.begin(); - sfIt != sources.end(); sfIt++) { - cmSourceFile* sf = *sfIt; + for (cmSourceFile* sf : sources) { if (sf->GetPropertyAsBool("GENERATED")) { continue; } @@ -278,11 +269,10 @@ std::string cmExtraKateGenerator::GenerateFilesString( const char* sep = ""; tmp = "\"list\": ["; - for (std::set::const_iterator it = files.begin(); - it != files.end(); ++it) { + for (std::string const& f : files) { tmp += sep; tmp += " \""; - tmp += *it; + tmp += f; tmp += "\""; sep = ","; } diff --git a/Source/cmExtraKateGenerator.h b/Source/cmExtraKateGenerator.h index 6b9c7af5c..9716fe750 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; diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 1fd1418de..73a9c8521 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -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 >::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); } } @@ -144,20 +142,19 @@ void cmExtraSublimeTextGenerator::CreateNewProjectFile( fout << "\n\t{"; fout << "\n\t\t" << systemName << ":"; fout << "\n\t\t{"; - for (std::vector::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; + << ", corrupted string " << t; mf->IssueMessage(cmake::FATAL_ERROR, e.str()); } } @@ -174,28 +171,26 @@ void cmExtraSublimeTextGenerator::AppendAllTargets( 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::const_iterator lg = lgs.begin(); - lg != lgs.end(); lg++) { - cmMakefile* makefile = (*lg)->GetMakefile(); - std::vector targets = (*lg)->GetGeneratorTargets(); - for (std::vector::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& 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 (strcmp(lg->GetCurrentBinaryDirectory(), + lg->GetBinaryDirectory()) == 0) { + this->AppendTarget(fout, targetName, lg, nullptr, make.c_str(), makefile, compiler.c_str(), sourceFileFlags, false); } @@ -212,7 +207,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 +216,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 +239,11 @@ void cmExtraSublimeTextGenerator::AppendTarget( MapSourceFileFlags& sourceFileFlags, bool firstTarget) { - if (target != CM_NULLPTR) { + if (target != nullptr) { std::vector sourceFiles; target->GetSourceFiles(sourceFiles, makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); - std::vector::const_iterator sourceFilesEnd = - sourceFiles.end(); - for (std::vector::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,8 +254,9 @@ void cmExtraSublimeTextGenerator::AppendTarget( .first; } std::vector& 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); flags.clear(); cmsys::RegularExpression flagRegex; // Regular expression to extract compiler flags from a string @@ -282,7 +274,7 @@ void cmExtraSublimeTextGenerator::AppendTarget( if (flagRegex.end() < workString.size()) { workString = workString.substr(flagRegex.end()); } else { - workString = ""; + workString.clear(); } } } diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h index 9022d3754..7fb304e11 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 > MapSourceFileFlags; + typedef std::map> MapSourceFileFlags; cmExtraSublimeTextGenerator(); - void Generate() CM_OVERRIDE; + void Generate() override; private: void CreateProjectFile(const std::vector& lgs); diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index ff78f52e3..03d1ad1f6 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -72,8 +72,8 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector 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); 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 #include @@ -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 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..fdd5f0c81 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -10,6 +10,7 @@ #include "cmsys/String.hxx" #include #include +#include // IWYU pragma: keep #include #include #include @@ -30,7 +31,6 @@ #include "cmPolicies.h" #include "cmSystemTools.h" #include "cmTimestamp.h" -#include "cm_auto_ptr.hxx" #include "cm_sys_stat.h" #include "cmake.h" @@ -55,14 +55,14 @@ class cmSystemToolsFileTime; 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; +static mode_t mode_group_read = 040; +static mode_t mode_group_write = 020; +static mode_t mode_group_execute = 010; +static mode_t mode_world_read = 04; +static mode_t mode_world_write = 02; +static mode_t mode_world_execute = 01; +static mode_t mode_setuid = 04000; +static mode_t mode_setgid = 02000; #else static mode_t mode_owner_read = S_IRUSR; static mode_t mode_owner_write = S_IWUSR; @@ -269,17 +269,17 @@ bool cmFileCommand::HandleReadCommand(std::vector const& args) cmCommandArgumentGroup group; cmCAString readArg(&argHelper, "READ"); - cmCAString fileNameArg(&argHelper, CM_NULLPTR); - cmCAString resultArg(&argHelper, CM_NULLPTR); + cmCAString fileNameArg(&argHelper, nullptr); + cmCAString resultArg(&argHelper, nullptr); cmCAString offsetArg(&argHelper, "OFFSET", &group); cmCAString limitArg(&argHelper, "LIMIT", &group); cmCAEnabler hexOutputArg(&argHelper, "HEX", &group); - readArg.Follows(CM_NULLPTR); + readArg.Follows(nullptr); fileNameArg.Follows(&readArg); resultArg.Follows(&fileNameArg); group.Follows(&resultArg); - argHelper.Parse(&args, CM_NULLPTR); + argHelper.Parse(&args, nullptr); std::string fileName = fileNameArg.GetString(); if (!cmsys::SystemTools::FileIsFullPath(fileName.c_str())) { @@ -368,8 +368,8 @@ bool cmFileCommand::HandleHashCommand(std::vector const& args) return false; } - CM_AUTO_PTR hash(cmCryptoHash::New(args[0].c_str())); - if (hash.get()) { + std::unique_ptr 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()); @@ -656,7 +656,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector const& args) c = current_str[current_str.size() - 1 - j]; fin.putback(static_cast(c)); } - current_str = ""; + current_str.clear(); } } @@ -667,14 +667,14 @@ bool cmFileCommand::HandleStringsCommand(std::vector const& args) if (s.length() >= minlen && (!have_regex || regex.find(s.c_str()))) { output_size += static_cast(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 @@ -683,14 +683,14 @@ bool cmFileCommand::HandleStringsCommand(std::vector const& args) (!have_regex || regex.find(s.c_str()))) { output_size += static_cast(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; } @@ -700,12 +700,12 @@ bool cmFileCommand::HandleStringsCommand(std::vector const& args) if (s.length() >= minlen && (!have_regex || regex.find(s.c_str()))) { output_size += static_cast(s.size()) + 1; if (limit_output >= 0 && output_size >= limit_output) { - s = ""; + s.clear(); break; } strings.push_back(s); } - s = ""; + s.clear(); } } @@ -723,20 +723,18 @@ bool cmFileCommand::HandleStringsCommand(std::vector const& args) // Encode the result in a CMake list. const char* sep = ""; std::string output; - for (std::vector::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; } } @@ -841,17 +839,16 @@ bool cmFileCommand::HandleGlobCommand(std::vector const& args, if (!globMessages.empty()) { bool shouldExit = false; - for (cmsys::Glob::GlobMessagesIterator it = globMessages.begin(); - it != globMessages.end(); ++it) { - if (it->type == cmsys::Glob::cyclicRecursion) { + for (cmsys::Glob::Message const& globMessage : globMessages) { + if (globMessage.type == cmsys::Glob::cyclicRecursion) { this->Makefile->IssueMessage( cmake::AUTHOR_WARNING, "Cyclic recursion detected while globbing for '" + *i + "':\n" + - it->content); + globMessage.content); } else { this->Makefile->IssueMessage( cmake::FATAL_ERROR, "Error has occurred while globbing for '" + - *i + "' - " + it->content); + *i + "' - " + globMessage.content); shouldExit = true; } } @@ -940,9 +937,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, @@ -997,7 +994,7 @@ struct cmFileCopier , MatchlessFiles(true) , FilePermissions(0) , DirPermissions(0) - , CurrentMatchRule(CM_NULLPTR) + , CurrentMatchRule(nullptr) , UseGivenPermissionsFile(false) , UseGivenPermissionsDir(false) , UseSourcePermissions(true) @@ -1060,12 +1057,11 @@ protected: // Collect properties from all matching rules. bool matched = false; MatchProperties result; - for (std::vector::iterator mr = this->MatchRules.begin(); - mr != this->MatchRules.end(); ++mr) { - if (mr->Regex.find(file_to_match)) { + for (MatchRule& mr : this->MatchRules) { + if (mr.Regex.find(file_to_match)) { matched = true; - result.Exclude |= mr->Properties.Exclude; - result.Permissions |= mr->Properties.Permissions; + result.Exclude |= mr.Properties.Exclude; + result.Permissions |= mr.Properties.Permissions; } } if (!matched && !this->MatchlessFiles) { @@ -1076,11 +1072,26 @@ protected: 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; + if (permissions) { +#ifdef WIN32 + if (Makefile->IsOn("CMAKE_CROSSCOMPILING")) { + std::string mode_t_adt_filename = + std::string(toFile) + ":cmake_mode_t"; + + cmsys::ofstream permissionStream(mode_t_adt_filename.c_str()); + + if (permissionStream) { + permissionStream << std::oct << permissions << std::endl; + } + } +#endif + + if (!cmSystemTools::SetPermissions(toFile, permissions)) { + std::ostringstream e; + e << this->Name << " cannot set permissions on \"" << toFile << "\""; + this->FileCommand->SetError(e.str()); + return false; + } } return true; } @@ -1406,23 +1417,22 @@ bool cmFileCopier::Run(std::vector const& args) return false; } - for (std::vector::const_iterator i = this->Files.begin(); - i != this->Files.end(); ++i) { + for (std::string const& f : this->Files) { std::string file; - if (!i->empty() && !cmSystemTools::FileIsFullPath(*i)) { + if (!f.empty() && !cmSystemTools::FileIsFullPath(f)) { if (!this->FilesFromDir.empty()) { file = this->FilesFromDir; } else { file = this->Makefile->GetCurrentSourceDirectory(); } file += "/"; - file += *i; + file += f; } 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; + file = f; } // Split the input file into its directory and name components. @@ -1435,7 +1445,7 @@ bool cmFileCopier::Run(std::vector const& args) // Compute the full path to the destination file. std::string toFile = this->Destination; if (!this->FilesFromDir.empty()) { - std::string dir = cmSystemTools::GetFilenamePath(*i); + std::string dir = cmSystemTools::GetFilenamePath(f); if (!dir.empty()) { toFile += "/"; toFile += dir; @@ -1696,7 +1706,7 @@ struct cmFileInstaller : public cmFileCopier this->Manifest = this->Makefile->GetSafeDefinition("CMAKE_INSTALL_MANIFEST_FILES"); } - ~cmFileInstaller() CM_OVERRIDE + ~cmFileInstaller() override { // Save the updated install manifest. this->Makefile->AddDefinition("CMAKE_INSTALL_MANIFEST_FILES", @@ -1721,12 +1731,12 @@ protected: this->Manifest += file.substr(this->DestDirLength); } - std::string const& ToName(std::string const& fromName) CM_OVERRIDE + std::string const& ToName(std::string const& fromName) override { return this->Rename.empty() ? fromName : this->Rename; } - void ReportCopy(const char* toFile, Type type, bool copy) CM_OVERRIDE + void ReportCopy(const char* toFile, Type type, bool copy) override { if (!this->MessageNever && (copy || !this->MessageLazy)) { std::string message = (copy ? "Installing: " : "Up-to-date: "); @@ -1738,11 +1748,11 @@ protected: this->ManifestAppend(toFile); } } - bool ReportMissing(const char* fromFile) CM_OVERRIDE + bool ReportMissing(const char* fromFile) override { return (this->Optional || this->cmFileCopier::ReportMissing(fromFile)); } - bool Install(const char* fromFile, const char* toFile) CM_OVERRIDE + bool Install(const char* fromFile, const char* toFile) override { // Support installing from empty source to make a directory. if (this->InstallType == cmInstallType_DIRECTORY && !*fromFile) { @@ -1751,16 +1761,16 @@ protected: return this->cmFileCopier::Install(fromFile, toFile); } - bool Parse(std::vector const& args) CM_OVERRIDE; + bool Parse(std::vector const& args) 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 + bool CheckKeyword(std::string const& arg) override; + bool CheckValue(std::string const& arg) override; + void DefaultFilePermissions() override { this->cmFileCopier::DefaultFilePermissions(); // Add execute permissions based on the target type. @@ -2028,9 +2038,9 @@ bool cmFileCommand::HandleRPathChangeCommand( std::vector const& args) { // Evaluate arguments. - const char* file = CM_NULLPTR; - const char* oldRPath = CM_NULLPTR; - const char* newRPath = CM_NULLPTR; + const char* file = nullptr; + const char* oldRPath = nullptr; + const char* newRPath = nullptr; enum Doing { DoingNone, @@ -2118,7 +2128,7 @@ bool cmFileCommand::HandleRPathRemoveCommand( std::vector const& args) { // Evaluate arguments. - const char* file = CM_NULLPTR; + const char* file = nullptr; enum Doing { DoingNone, @@ -2182,8 +2192,8 @@ bool cmFileCommand::HandleRPathCheckCommand( std::vector const& args) { // Evaluate arguments. - const char* file = CM_NULLPTR; - const char* rpath = CM_NULLPTR; + const char* file = nullptr; + const char* rpath = nullptr; enum Doing { DoingNone, @@ -2241,16 +2251,16 @@ bool cmFileCommand::HandleReadElfCommand(std::vector const& args) cmCommandArgumentGroup group; cmCAString readArg(&argHelper, "READ_ELF"); - cmCAString fileNameArg(&argHelper, CM_NULLPTR); + cmCAString fileNameArg(&argHelper, nullptr); cmCAString rpathArg(&argHelper, "RPATH", &group); cmCAString runpathArg(&argHelper, "RUNPATH", &group); cmCAString errorArg(&argHelper, "CAPTURE_ERROR", &group); - readArg.Follows(CM_NULLPTR); + readArg.Follows(nullptr); fileNameArg.Follows(&readArg); group.Follows(&fileNameArg); - argHelper.Parse(&args, CM_NULLPTR); + argHelper.Parse(&args, nullptr); if (!cmSystemTools::FileExists(fileNameArg.GetString(), true)) { std::ostringstream e; @@ -2284,10 +2294,9 @@ bool cmFileCommand::HandleReadElfCommand(std::vector const& args) if (errorArg.GetString().empty()) { this->SetError(error); return false; - } else { - this->Makefile->AddDefinition(errorArg.GetString(), error.c_str()); - return true; } + this->Makefile->AddDefinition(errorArg.GetString(), error.c_str()); + return true; #endif } @@ -2439,7 +2448,7 @@ namespace { size_t cmWriteToFileCallback(void* ptr, size_t size, size_t nmemb, void* data) { - int realsize = (int)(size * nmemb); + int realsize = static_cast(size * nmemb); cmsys::ofstream* fout = static_cast(data); const char* chPtr = static_cast(ptr); fout->write(chPtr, realsize); @@ -2449,7 +2458,7 @@ 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); + int realsize = static_cast(size * nmemb); cmFileCommandVectorOfChar* vec = static_cast(data); const char* chPtr = static_cast(ptr); @@ -2581,7 +2590,7 @@ public: } } - void release() { this->Easy = CM_NULLPTR; } + void release() { this->Easy = nullptr; } private: ::CURL* Easy; @@ -2619,7 +2628,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector const& args) const char* cainfo = this->Makefile->GetDefinition("CMAKE_TLS_CAINFO"); std::string expectedHash; std::string hashMatchMSG; - CM_AUTO_PTR hash; + std::unique_ptr hash; bool showProgress = false; std::string userpwd; @@ -2678,8 +2687,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector const& args) this->SetError("DOWNLOAD missing sum value for EXPECTED_MD5."); return false; } - hash = - CM_AUTO_PTR(new cmCryptoHash(cmCryptoHash::AlgoMD5)); + hash = cm::make_unique(cmCryptoHash::AlgoMD5); hashMatchMSG = "MD5 sum"; expectedHash = cmSystemTools::LowerCase(*i); } else if (*i == "SHOW_PROGRESS") { @@ -2700,7 +2708,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector const& args) } std::string algo = i->substr(0, pos); expectedHash = cmSystemTools::LowerCase(i->substr(pos + 1)); - hash = CM_AUTO_PTR(cmCryptoHash::New(algo.c_str())); + hash = std::unique_ptr(cmCryptoHash::New(algo.c_str())); if (!hash.get()) { std::string err = "DOWNLOAD EXPECTED_HASH given unknown ALGO: "; err += algo; @@ -2743,7 +2751,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector 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; @@ -2816,10 +2824,10 @@ bool cmFileCommand::HandleDownloadCommand(std::vector const& args) 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 +2874,9 @@ bool cmFileCommand::HandleDownloadCommand(std::vector const& args) check_curl_result(res, "DOWNLOAD cannot set user password: "); } - struct curl_slist* headers = CM_NULLPTR; - for (std::vector::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 +2890,8 @@ bool cmFileCommand::HandleDownloadCommand(std::vector const& args) if (!statusVar.empty()) { std::ostringstream result; - result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\""; + result << static_cast(res) << ";\"" << ::curl_easy_strerror(res) + << "\""; this->Makefile->AddDefinition(statusVar, result.str().c_str()); } @@ -2896,7 +2904,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector 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 +2917,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector const& args) << " for file: [" << file << "]" << std::endl << " expected hash: [" << expectedHash << "]" << std::endl << " actual hash: [" << actualHash << "]" << std::endl - << " status: [" << (int)res << ";\"" + << " status: [" << static_cast(res) << ";\"" << ::curl_easy_strerror(res) << "\"]" << std::endl; if (!statusVar.empty() && res == 0) { @@ -3065,10 +3073,10 @@ bool cmFileCommand::HandleUploadCommand(std::vector 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 +3132,9 @@ bool cmFileCommand::HandleUploadCommand(std::vector const& args) check_curl_result(res, "UPLOAD cannot set user password: "); } - struct curl_slist* headers = CM_NULLPTR; - for (std::vector::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); @@ -3141,14 +3148,15 @@ bool cmFileCommand::HandleUploadCommand(std::vector const& args) if (!statusVar.empty()) { std::ostringstream result; - result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\""; + result << static_cast(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; @@ -3185,15 +3193,15 @@ void cmFileCommand::AddEvaluationFile(const std::string& inputName, cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); cmGeneratorExpression outputGe(lfbt); - CM_AUTO_PTR outputCge = + std::unique_ptr outputCge = outputGe.Parse(outputExpr); cmGeneratorExpression conditionGe(lfbt); - CM_AUTO_PTR conditionCge = + std::unique_ptr 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 const& args) diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h index d09ef42f1..17269f3f9 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; protected: bool HandleRename(std::vector const& args); diff --git a/Source/cmFileLock.cxx b/Source/cmFileLock.cxx index 786d6c63f..f309241a6 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; diff --git a/Source/cmFileLock.h b/Source/cmFileLock.h index ccef50816..c9ab0dbcb 100644 --- a/Source/cmFileLock.h +++ b/Source/cmFileLock.h @@ -3,7 +3,7 @@ #ifndef cmFileLock_h #define cmFileLock_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include diff --git a/Source/cmFileLockPool.cxx b/Source/cmFileLockPool.cxx index 7b1564c34..5dc9243a1 100644 --- a/Source/cmFileLockPool.cxx +++ b/Source/cmFileLockPool.cxx @@ -75,16 +75,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 +94,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; } @@ -138,9 +136,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 +147,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..af982707e 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 #include 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 #include +#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/cmFileMonitor.cxx b/Source/cmFileMonitor.cxx index 80275357c..04a3c0ef7 100644 --- a/Source/cmFileMonitor.cxx +++ b/Source/cmFileMonitor.cxx @@ -49,8 +49,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 +62,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 WatchedFiles() const final { std::vector 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 +88,9 @@ public: std::vector WatchedDirectories() const override { std::vector 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; @@ -171,7 +171,9 @@ public: { if (this->Handle) { uv_fs_event_stop(this->Handle); - uv_close(reinterpret_cast(this->Handle), &on_fs_close); + if (!uv_is_closing(reinterpret_cast(this->Handle))) { + uv_close(reinterpret_cast(this->Handle), &on_fs_close); + } this->Handle = nullptr; } cmVirtualDirectoryWatcher::StopWatching(); @@ -182,8 +184,9 @@ public: std::vector WatchedDirectories() const override { std::vector 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 +268,7 @@ public: static_cast(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,7 +312,7 @@ cmFileMonitor::~cmFileMonitor() void cmFileMonitor::MonitorPaths(const std::vector& paths, Callback const& cb) { - for (const auto& p : paths) { + for (std::string const& p : paths) { std::vector pathSegments; cmsys::SystemTools::SplitPath(p, pathSegments, true); diff --git a/Source/cmFileMonitor.h b/Source/cmFileMonitor.h index d7ec92a17..632e7514f 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 #include diff --git a/Source/cmFilePathChecksum.cxx b/Source/cmFilePathChecksum.cxx index 62f52e590..f9afeefcd 100644 --- a/Source/cmFilePathChecksum.cxx +++ b/Source/cmFilePathChecksum.cxx @@ -13,10 +13,10 @@ cmFilePathChecksum::cmFilePathChecksum() { } -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 +29,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 = cmsys::SystemTools::GetRealPath(currentSrcDir); + this->parentDirs[1].first = cmsys::SystemTools::GetRealPath(currentBinDir); + this->parentDirs[2].first = cmsys::SystemTools::GetRealPath(projectSrcDir); + this->parentDirs[3].first = cmsys::SystemTools::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 = cmsys::SystemTools::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 +76,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.front(), 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..48b5da0f0 100644 --- a/Source/cmFilePathChecksum.h +++ b/Source/cmFilePathChecksum.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include #include #include #include @@ -29,37 +30,35 @@ public: cmFilePathChecksum(); /// @brief Initilizes the parent directories manually - cmFilePathChecksum(const std::string& currentSrcDir, - const std::string& currentBinDir, - const std::string& projectSrcDir, - const std::string& projectBinDir); + 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 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 parentDirs[numParentDirs]; + std::array, 4> parentDirs; }; #endif diff --git a/Source/cmFileTimeComparison.cxx b/Source/cmFileTimeComparison.cxx index f591a8dc7..622c15e2c 100644 --- a/Source/cmFileTimeComparison.cxx +++ b/Source/cmFileTimeComparison.cxx @@ -4,10 +4,9 @@ #include #include +#include #include -#include "cm_unordered_map.hxx" - // Use a platform-specific API to get file times efficiently. #if !defined(_WIN32) || defined(__CYGWIN__) #include "cm_sys_stat.h" @@ -27,7 +26,7 @@ public: bool FileTimesDiffer(const char* f1, const char* f2); private: - typedef CM_UNORDERED_MAP + typedef std::unordered_map FileStatsMap; FileStatsMap Files; @@ -117,18 +116,22 @@ int cmFileTimeComparisonInternal::Compare(cmFileTimeComparison_Type* s1, // Compare using nanosecond resolution. if (s1->st_mtimespec.tv_sec < s2->st_mtimespec.tv_sec) { return -1; - } else if (s1->st_mtimespec.tv_sec > s2->st_mtimespec.tv_sec) { + } + if (s1->st_mtimespec.tv_sec > s2->st_mtimespec.tv_sec) { return 1; - } else if (s1->st_mtimespec.tv_nsec < s2->st_mtimespec.tv_nsec) { + } + if (s1->st_mtimespec.tv_nsec < s2->st_mtimespec.tv_nsec) { return -1; - } else if (s1->st_mtimespec.tv_nsec > s2->st_mtimespec.tv_nsec) { + } + if (s1->st_mtimespec.tv_nsec > s2->st_mtimespec.tv_nsec) { return 1; } #else // Compare using 1 second resolution. if (s1->st_mtime < s2->st_mtime) { return -1; - } else if (s1->st_mtime > s2->st_mtime) { + } + if (s1->st_mtime > s2->st_mtime) { return 1; } #endif @@ -163,20 +166,20 @@ bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1, long long t2 = s2->st_mtimespec.tv_sec * bil + s2->st_mtimespec.tv_nsec; if (t1 < t2) { return (t2 - t1) >= bil; - } else if (t2 < t1) { + } + if (t2 < t1) { return (t1 - t2) >= bil; - } else { - return false; } + return false; #else // Times are integers in units of 1s. if (s1->st_mtime < s2->st_mtime) { return (s2->st_mtime - s1->st_mtime) >= 1; - } else if (s1->st_mtime > s2->st_mtime) { + } + if (s1->st_mtime > s2->st_mtime) { return (s1->st_mtime - s2->st_mtime) >= 1; - } else { - return false; } + return false; #endif #else // Times are integers in units of 100ns. diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index 10c6fe46f..417cdd25c 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmFindBase.h" -#include "cmConfigure.h" #include #include #include @@ -281,10 +280,8 @@ void cmFindBase::FillUserHintsPath() { cmSearchPath& paths = this->LabeledPaths[PathLabel::Hints]; - for (std::vector::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 +290,8 @@ void cmFindBase::FillUserGuessPath() { cmSearchPath& paths = this->LabeledPaths[PathLabel::Guess]; - for (std::vector::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 +330,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..814296201 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -155,10 +155,9 @@ void cmFindCommon::SelectDefaultMacMode() void cmFindCommon::RerootPaths(std::vector& paths) { #if 0 - for(std::vector::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. @@ -194,9 +193,8 @@ void cmFindCommon::RerootPaths(std::vector& paths) if (sysroot) { roots.push_back(sysroot); } - for (std::vector::iterator ri = roots.begin(); - ri != roots.end(); ++ri) { - cmSystemTools::ConvertToUnixSlashes(*ri); + for (std::string& r : roots) { + cmSystemTools::ConvertToUnixSlashes(r); } const char* stagePrefix = @@ -206,24 +204,22 @@ void cmFindCommon::RerootPaths(std::vector& paths) std::vector unrootedPaths = paths; paths.clear(); - for (std::vector::const_iterator ri = roots.begin(); - ri != roots.end(); ++ri) { - for (std::vector::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. @@ -242,22 +238,21 @@ void cmFindCommon::GetIgnoredPaths(std::vector& 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::iterator i = ignore.begin(); - i != ignore.end(); ++i) { - cmSystemTools::ConvertToUnixSlashes(*i); + for (std::string& i : ignore) { + cmSystemTools::ConvertToUnixSlashes(i); } } @@ -337,9 +332,8 @@ void cmFindCommon::ComputeFinalPaths() // Combine the seperate path types, filtering out ignores this->SearchPaths.clear(); std::vector& allLabels = this->PathGroupLabelMap[PathGroup::All]; - for (std::vector::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..b237f1bd1 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 #include @@ -25,7 +25,7 @@ class cmFindCommon : public cmCommand { public: cmFindCommon(); - ~cmFindCommon() CM_OVERRIDE; + ~cmFindCommon() override; protected: friend class cmSearchPath; @@ -112,7 +112,7 @@ protected: std::vector SearchPathSuffixes; - std::map > PathGroupLabelMap; + std::map> PathGroupLabelMap; std::vector PathGroupOrder; std::map PathLabelStringMap; std::map 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..758da2ce0 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -68,8 +68,8 @@ bool cmFindLibraryCommand::InitialPass(std::vector 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 +87,8 @@ void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix) { std::vector original; original.swap(this->SearchPaths); - for (std::vector::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); } } @@ -254,15 +253,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(tolower(ch)); #else out += ch; #endif @@ -276,23 +274,20 @@ void cmFindLibraryHelper::RegexFromList(std::string& out, // else and the result can be checked after matching. out += "("; const char* sep = ""; - for (std::vector::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::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; } @@ -339,9 +334,8 @@ void cmFindLibraryHelper::SetName(std::string const& name) bool cmFindLibraryHelper::CheckDirectory(std::string const& path) { - for (std::vector::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; } } @@ -376,9 +370,7 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, std::string dir = path; cmSystemTools::ConvertToUnixSlashes(dir); std::set const& files = this->GG->GetDirectoryContent(dir); - for (std::set::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 +422,12 @@ std::string cmFindLibraryCommand::FindNormalLibraryNamesPerDir() { // Search for all names in each directory. cmFindLibraryHelper helper(this->Makefile); - for (std::vector::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::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 +439,13 @@ std::string cmFindLibraryCommand::FindNormalLibraryDirsPerName() { // Search the entire path for each name. cmFindLibraryHelper helper(this->Makefile); - for (std::vector::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::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 +466,10 @@ std::string cmFindLibraryCommand::FindFrameworkLibraryNamesPerDir() { std::string fwPath; // Search for all names in each search path. - for (std::vector::const_iterator di = this->SearchPaths.begin(); - di != this->SearchPaths.end(); ++di) { - for (std::vector::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 +485,10 @@ std::string cmFindLibraryCommand::FindFrameworkLibraryDirsPerName() { std::string fwPath; // Search for each name in all search paths. - for (std::vector::const_iterator ni = this->Names.begin(); - ni != this->Names.end(); ++ni) { - for (std::vector::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 #include @@ -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 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..5a7265581 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -13,6 +13,7 @@ #include #include #include +#include // IWYU pragma: keep #include #include #include @@ -24,7 +25,6 @@ #include "cmState.h" #include "cmStateTypes.h" #include "cmVersion.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(__HAIKU__) @@ -367,14 +367,12 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args, if (!this->UseFindModules && !this->UseConfigFiles) { std::ostringstream e; e << "given options exclusive to Module mode:\n"; - for (std::set::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::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()); @@ -518,13 +516,12 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args, // Add the default configs. if (this->Configs.empty()) { - for (std::vector::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); } @@ -611,14 +608,12 @@ void cmFindPackageCommand::AddFindDefinition(const std::string& var, void cmFindPackageCommand::RestoreFindDefinitions() { - for (std::map::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); } } } @@ -874,13 +869,11 @@ bool cmFindPackageCommand::HandlePackageMode() std::string consideredVersions; const char* sep = ""; - for (std::vector::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 +939,8 @@ bool cmFindPackageCommand::FindConfig() bool cmFindPackageCommand::FindPrefixedConfig() { std::vector const& prefixes = this->SearchPaths; - for (std::vector::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 +950,8 @@ bool cmFindPackageCommand::FindPrefixedConfig() bool cmFindPackageCommand::FindFrameworkConfig() { std::vector const& prefixes = this->SearchPaths; - for (std::vector::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,9 +961,8 @@ bool cmFindPackageCommand::FindFrameworkConfig() bool cmFindPackageCommand::FindAppBundleConfig() { std::vector const& prefixes = this->SearchPaths; - for (std::vector::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; } } @@ -1171,14 +1161,12 @@ void cmFindPackageCommand::FillPrefixesSystemEnvironment() // working directory. std::vector tmp; cmSystemTools::GetPath(tmp); - for (std::vector::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); } } } @@ -1296,9 +1284,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::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 +1306,7 @@ public: cmSystemTools::RemoveFile(this->File); } } - void Release() { this->File = CM_NULLPTR; } + void Release() { this->File = nullptr; } }; void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir, @@ -1395,10 +1382,8 @@ void cmFindPackageCommand::FillPrefixesUserGuess() { cmSearchPath& paths = this->LabeledPaths[PathLabel::Guess]; - for (std::vector::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,10 +1391,8 @@ void cmFindPackageCommand::FillPrefixesUserHints() { cmSearchPath& paths = this->LabeledPaths[PathLabel::Hints]; - for (std::vector::const_iterator p = - this->UserHintsArgs.begin(); - p != this->UserHintsArgs.end(); ++p) { - paths.AddUserPath(*p); + for (std::string const& p : this->UserHintsArgs) { + paths.AddUserPath(p); } } @@ -1418,12 +1401,10 @@ bool cmFindPackageCommand::SearchDirectory(std::string const& dir) assert(!dir.empty() && dir[dir.size() - 1] == '/'); // Check each path suffix on this directory. - for (std::vector::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)) { @@ -1454,11 +1435,10 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir, return false; } - for (std::vector::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()); } @@ -1631,10 +1611,10 @@ protected: private: bool Search(cmFileList&); virtual bool Search(std::string const& parent, cmFileList&) = 0; - virtual CM_AUTO_PTR Clone() const = 0; + virtual std::unique_ptr Clone() const = 0; friend class cmFileList; cmFileListGeneratorBase* SetNext(cmFileListGeneratorBase const& next); - CM_AUTO_PTR Next; + std::unique_ptr Next; }; class cmFileList @@ -1642,7 +1622,7 @@ class cmFileList public: cmFileList() : First() - , Last(CM_NULLPTR) + , Last(nullptr) { } virtual ~cmFileList() {} @@ -1658,7 +1638,7 @@ public: } bool Search() { - if (this->First.get()) { + if (this->First) { return this->First->Search(*this); } return false; @@ -1667,7 +1647,7 @@ public: private: virtual bool Visit(std::string const& fullPath) = 0; friend class cmFileListGeneratorBase; - CM_AUTO_PTR First; + std::unique_ptr First; cmFileListGeneratorBase* Last; }; @@ -1682,7 +1662,7 @@ public: } 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 +1688,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 + "/"); @@ -1730,14 +1710,14 @@ public: 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 Clone() const CM_OVERRIDE + std::unique_ptr Clone() const override { - CM_AUTO_PTR g( + std::unique_ptr g( new cmFileListGeneratorFixed(*this)); return g; } @@ -1759,19 +1739,18 @@ public: private: std::vector const& Vector; - bool Search(std::string const& parent, cmFileList& lister) CM_OVERRIDE + bool Search(std::string const& parent, cmFileList& lister) override { - for (std::vector::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 Clone() const CM_OVERRIDE + std::unique_ptr Clone() const override { - CM_AUTO_PTR g( + std::unique_ptr g( new cmFileListGeneratorEnumerate(*this)); return g; } @@ -1809,7 +1788,7 @@ protected: private: std::vector 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 matches; @@ -1820,9 +1799,8 @@ private: if (strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0) { continue; } - for (std::vector::const_iterator ni = this->Names.begin(); - ni != this->Names.end(); ++ni) { - if (cmsysString_strncasecmp(fname, ni->c_str(), ni->length()) == 0) { + for (std::string const& n : this->Names) { + if (cmsysString_strncasecmp(fname, n.c_str(), n.length()) == 0) { matches.push_back(fname); } } @@ -1835,17 +1813,16 @@ private: SortDirection); } - for (std::vector::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 Clone() const CM_OVERRIDE + std::unique_ptr Clone() const override { - CM_AUTO_PTR g( + std::unique_ptr g( new cmFileListGeneratorProject(*this)); return g; } @@ -1871,7 +1848,7 @@ public: private: std::vector 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 matches; @@ -1882,9 +1859,7 @@ private: if (strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0) { continue; } - for (std::vector::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); @@ -1892,17 +1867,16 @@ private: } } - for (std::vector::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 Clone() const CM_OVERRIDE + std::unique_ptr Clone() const override { - CM_AUTO_PTR g( + std::unique_ptr g( new cmFileListGeneratorMacProject(*this)); return g; } @@ -1925,7 +1899,7 @@ public: 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 matches; @@ -1944,9 +1918,9 @@ private: } return false; } - CM_AUTO_PTR Clone() const CM_OVERRIDE + std::unique_ptr Clone() const override { - CM_AUTO_PTR g( + std::unique_ptr g( new cmFileListGeneratorCaseInsensitive(*this)); return g; } @@ -1968,7 +1942,7 @@ public: 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,20 +1954,18 @@ private: std::vector const& files = g.GetFiles(); // Look for directories among the matches. - for (std::vector::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 Clone() const CM_OVERRIDE + std::unique_ptr Clone() const override { - CM_AUTO_PTR g(new cmFileListGeneratorGlob(*this)); - return g; + return cm::make_unique(*this); } }; diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 99b0059ba..150a51d14 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -3,7 +3,7 @@ #ifndef cmFindPackageCommand_h #define cmFindPackageCommand_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cm_kwiml.h" #include @@ -51,14 +51,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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: class PathLabel : public cmFindCommon::PathLabel diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx index d3541ca94..ea2641001 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; @@ -124,18 +124,15 @@ std::string cmFindPathCommand::FindHeaderInFramework(std::string const& file, std::string cmFindPathCommand::FindNormalHeader() { std::string tryPath; - for (std::vector::const_iterator ni = this->Names.begin(); - ni != this->Names.end(); ++ni) { - for (std::vector::const_iterator p = - this->SearchPaths.begin(); - p != this->SearchPaths.end(); ++p) { - tryPath = *p; - tryPath += *ni; + for (std::string const& n : this->Names) { + for (std::string const& sp : this->SearchPaths) { + tryPath = sp; + tryPath += n; if (cmSystemTools::FileExists(tryPath.c_str())) { if (this->IncludeFileInPath) { return tryPath; } - return *p; + return sp; } } } @@ -144,12 +141,9 @@ std::string cmFindPathCommand::FindNormalHeader() std::string cmFindPathCommand::FindFrameworkHeader() { - for (std::vector::const_iterator ni = this->Names.begin(); - ni != this->Names.end(); ++ni) { - for (std::vector::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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; bool IncludeFileInPath; diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index 9327c1805..2059b3d65 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -45,9 +45,8 @@ struct cmFindProgramHelper } bool CheckDirectory(std::string const& path) { - for (std::vector::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,14 +54,13 @@ struct cmFindProgramHelper } bool CheckDirectoryForName(std::string const& path, std::string const& name) { - for (std::vector::iterator ext = this->Extensions.begin(); - ext != this->Extensions.end(); ++ext) { + for (std::string const& ext : this->Extensions) { this->TestPath = path; this->TestPath += name; - if (!ext->empty() && cmSystemTools::StringEndsWith(name, ext->c_str())) { + if (!ext.empty() && cmSystemTools::StringEndsWith(name, ext.c_str())) { continue; } - this->TestPath += *ext; + this->TestPath += ext; if (cmSystemTools::FileExists(this->TestPath, true)) { this->BestPath = cmSystemTools::CollapseFullPath(this->TestPath); return true; @@ -99,8 +97,8 @@ bool cmFindProgramCommand::InitialPass(std::vector 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,9 +141,8 @@ std::string cmFindProgramCommand::FindNormalProgramNamesPerDir() { // Search for all names in each directory. cmFindProgramHelper helper; - for (std::vector::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). @@ -154,9 +151,8 @@ std::string cmFindProgramCommand::FindNormalProgramNamesPerDir() } // Search every directory. - for (std::vector::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,10 +164,9 @@ std::string cmFindProgramCommand::FindNormalProgramDirsPerName() { // Search the entire path for each name. cmFindProgramHelper helper; - for (std::vector::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())) { @@ -179,10 +174,8 @@ std::string cmFindProgramCommand::FindNormalProgramDirsPerName() } // Search every directory. - for (std::vector::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 +186,9 @@ std::string cmFindProgramCommand::FindNormalProgramDirsPerName() std::string cmFindProgramCommand::FindAppBundle() { - for (std::vector::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 +229,7 @@ std::string cmFindProgramCommand::GetBundleExecutable( // returned executableURL is relative to /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 #include @@ -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 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..542a86025 100644 --- a/Source/cmForEachCommand.cxx +++ b/Source/cmForEachCommand.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmForEachCommand.h" +#include // IWYU pragma: keep #include #include #include @@ -9,7 +10,6 @@ #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmForEachFunctionBlocker::cmForEachFunctionBlocker(cmMakefile* mf) @@ -35,7 +35,8 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, // if this is the endofreach for this statement if (!this->Depth) { // Remove the function blocker for this scope or bail. - CM_AUTO_PTR fb(mf.RemoveFunctionBlocker(this, lff)); + std::unique_ptr fb( + mf.RemoveFunctionBlocker(this, lff)); if (!fb.get()) { return false; } @@ -54,9 +55,9 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, mf.AddDefinition(this->Args[0], j->c_str()); // Invoke all the functions that were collected in the block. cmExecutionStatus status; - for (unsigned int c = 0; c < this->Functions.size(); ++c) { + 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 @@ -181,7 +182,7 @@ bool cmForEachCommand::InitialPass(std::vector const& args, bool cmForEachCommand::HandleInMode(std::vector const& args) { - CM_AUTO_PTR f( + std::unique_ptr f( new cmForEachFunctionBlocker(this->Makefile)); f->Args.push_back(args[0]); @@ -213,7 +214,7 @@ bool cmForEachCommand::HandleInMode(std::vector const& args) } } - 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 #include @@ -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 Args; std::vector 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: bool HandleInMode(std::vector const& args); diff --git a/Source/cmFortranParser.h b/Source/cmFortranParser.h index d8b002309..3f5ad8744 100644 --- a/Source/cmFortranParser.h +++ b/Source/cmFortranParser.h @@ -4,7 +4,7 @@ #define cmFortranParser_h #if !defined(cmFortranLexer_cxx) && !defined(cmFortranParser_cxx) -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include diff --git a/Source/cmFortranParserImpl.cxx b/Source/cmFortranParserImpl.cxx index 4e23f3691..81f1286d2 100644 --- a/Source/cmFortranParserImpl.cxx +++ b/Source/cmFortranParserImpl.cxx @@ -3,7 +3,6 @@ #include "cmFortranParser.h" #include "cmSystemTools.h" -#include "cmConfigure.h" #include #include #include @@ -31,9 +30,8 @@ bool cmFortranParser_s::FindIncludeFile(const char* dir, } // Search the include path for the file. - for (std::vector::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)) { @@ -61,7 +59,7 @@ cmFortranParser_s::cmFortranParser_s(std::vector 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); } @@ -79,7 +77,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 +119,14 @@ int cmFortranParser_Input(cmFortranParser* parser, char* buffer, n = 1; ff.LastCharWasNewline = true; } - return (int)n; + return static_cast(n); } return 0; } void cmFortranParser_StringStart(cmFortranParser* parser) { - parser->TokenString = ""; + parser->TokenString.clear(); } const char* cmFortranParser_StringEnd(cmFortranParser* parser) diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index ee52bde37..774df849c 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -18,12 +18,12 @@ public: cmFunctionHelperCommand() {} ///! clean up any memory allocated by the function - ~cmFunctionHelperCommand() CM_OVERRIDE {} + ~cmFunctionHelperCommand() 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 +39,10 @@ public: * the CMakeLists.txt file. */ bool InvokeInitialPass(const std::vector& args, - cmExecutionStatus&) CM_OVERRIDE; + cmExecutionStatus&) override; bool InitialPass(std::vector const&, - cmExecutionStatus&) CM_OVERRIDE + cmExecutionStatus&) override { return false; } @@ -104,9 +104,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. diff --git a/Source/cmFunctionCommand.h b/Source/cmFunctionCommand.h index f26312632..3352b9235 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 #include @@ -19,10 +19,10 @@ class cmFunctionFunctionBlocker : public cmFunctionBlocker { public: cmFunctionFunctionBlocker() { this->Depth = 0; } - ~cmFunctionFunctionBlocker() CM_OVERRIDE {} + ~cmFunctionFunctionBlocker() 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 Args; std::vector Functions; @@ -36,14 +36,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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h index 56f9988ff..a96f38fa8 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" @@ -94,7 +94,7 @@ public: * file was successfully written before allowing the original to be * replaced. */ - ~cmGeneratedFileStream() CM_OVERRIDE; + ~cmGeneratedFileStream() override; /** * Open an output file by name. This should be used only with a diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 00b5ff4ef..86991c1c5 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -3,6 +3,7 @@ #include "cmGeneratorExpression.h" #include "cmsys/RegularExpression.hxx" +#include // IWYU pragma: keep #include #include "assert.h" @@ -12,7 +13,6 @@ #include "cmGeneratorExpressionLexer.h" #include "cmGeneratorExpressionParser.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" cmGeneratorExpression::cmGeneratorExpression( const cmListFileBacktrace& backtrace) @@ -20,14 +20,14 @@ cmGeneratorExpression::cmGeneratorExpression( { } -CM_AUTO_PTR cmGeneratorExpression::Parse( +std::unique_ptr cmGeneratorExpression::Parse( std::string const& input) { - return CM_AUTO_PTR( + return std::unique_ptr( new cmCompiledGeneratorExpression(this->Backtrace, input)); } -CM_AUTO_PTR cmGeneratorExpression::Parse( +std::unique_ptr cmGeneratorExpression::Parse( const char* input) { return this->Parse(std::string(input ? input : "")); @@ -68,7 +68,7 @@ const char* cmCompiledGeneratorExpression::EvaluateWithContext( return this->Input.c_str(); } - this->Output = ""; + this->Output.clear(); std::vector::const_iterator it = this->Evaluators.begin(); @@ -81,7 +81,7 @@ const char* cmCompiledGeneratorExpression::EvaluateWithContext( this->SeenTargetProperties.insert(context.SeenTargetProperties.begin(), context.SeenTargetProperties.end()); if (context.HadError) { - this->Output = ""; + this->Output.clear(); break; } } @@ -199,15 +199,14 @@ static void prefixItems(const std::string& content, std::string& result, std::vector entries; cmGeneratorExpression::Split(content, entries); const char* sep = ""; - for (std::vector::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.c_str()) && + cmGeneratorExpression::Find(e) != 0) { result += prefix; } - result += *ei; + result += e; } } @@ -297,7 +296,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); @@ -379,7 +378,7 @@ void cmCompiledGeneratorExpression::GetMaxLanguageStandard( const cmGeneratorTarget* tgt, std::map& mapping) { typedef std::map > + std::map> MapType; MapType::const_iterator it = this->MaxLanguageStandard.find(tgt); if (it != this->MaxLanguageStandard.end()) { diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index 34516f5c5..cface0d70 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -3,12 +3,12 @@ #ifndef cmGeneratorExpression_h #define cmGeneratorExpression_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmListFileCache.h" -#include "cm_auto_ptr.hxx" #include +#include // IWYU pragma: keep #include #include #include @@ -39,8 +39,9 @@ public: cmListFileBacktrace const& backtrace = cmListFileBacktrace()); ~cmGeneratorExpression(); - CM_AUTO_PTR Parse(std::string const& input); - CM_AUTO_PTR Parse(const char* input); + std::unique_ptr Parse( + std::string const& input); + std::unique_ptr Parse(const char* input); enum PreprocessContext { @@ -71,12 +72,12 @@ class cmCompiledGeneratorExpression CM_DISABLE_COPY(cmCompiledGeneratorExpression) public: - const char* Evaluate( - cmLocalGenerator* lg, const std::string& config, bool quiet = false, - cmGeneratorTarget const* headTarget = CM_NULLPTR, - cmGeneratorTarget const* currentTarget = CM_NULLPTR, - cmGeneratorExpressionDAGChecker* dagChecker = CM_NULLPTR, - std::string const& language = std::string()) const; + const char* 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; const char* Evaluate(cmLocalGenerator* lg, const std::string& config, bool quiet, cmGeneratorTarget const* headTarget, cmGeneratorExpressionDAGChecker* dagChecker, @@ -143,7 +144,7 @@ private: mutable std::set AllTargetsSeen; mutable std::set SeenTargetProperties; mutable std::map > + std::map> MaxLanguageStandard; mutable std::string Output; mutable bool HadContextSensitiveCondition; diff --git a/Source/cmGeneratorExpressionContext.h b/Source/cmGeneratorExpressionContext.h index cf292dcef..5b0123ec8 100644 --- a/Source/cmGeneratorExpressionContext.h +++ b/Source/cmGeneratorExpressionContext.h @@ -26,7 +26,7 @@ struct cmGeneratorExpressionContext std::set AllTargets; std::set SeenTargetProperties; std::set SourceSensitiveTargets; - std::map > + std::map> MaxLanguageStandard; cmLocalGenerator* LG; std::string Config; diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index c0266311b..f0eafb46a 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -58,7 +58,7 @@ void cmGeneratorExpressionDAGChecker::Initialize() TEST_TRANSITIVE_PROPERTY_METHOD) false)) // NOLINT(clang-tidy) #undef TEST_TRANSITIVE_PROPERTY_METHOD { - std::map >::const_iterator it = + std::map>::const_iterator it = top->Seen.find(this->Target); if (it != top->Seen.end()) { const std::set& propSet = it->second; diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index 557a19220..3f73fca8a 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" @@ -61,7 +61,7 @@ struct cmGeneratorExpressionDAGChecker void ReportError(cmGeneratorExpressionContext* context, const std::string& expr); - bool EvaluatingLinkLibraries(const char* tgt = CM_NULLPTR); + bool EvaluatingLinkLibraries(const char* tgt = nullptr); #define DECLARE_TRANSITIVE_PROPERTY_METHOD(METHOD) bool METHOD() const; @@ -82,7 +82,7 @@ private: const cmGeneratorExpressionDAGChecker* const Parent; const std::string Target; const std::string Property; - std::map > Seen; + std::map> Seen; const GeneratorExpressionContent* const Content; const cmListFileBacktrace Backtrace; Result CheckResult; diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index 15264545b..87b6b342d 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 // IWYU pragma: keep #include #include @@ -14,17 +14,18 @@ #include "cmMakefile.h" #include "cmSourceFile.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmGeneratorExpressionEvaluationFile::cmGeneratorExpressionEvaluationFile( const std::string& input, - CM_AUTO_PTR outputFileExpr, - CM_AUTO_PTR condition, bool inputIsContent) + std::unique_ptr outputFileExpr, + std::unique_ptr condition, + bool inputIsContent, cmPolicies::PolicyStatus policyStatusCMP0070) : Input(input) - , OutputFileExpr(outputFileExpr) - , Condition(condition) + , OutputFileExpr(std::move(outputFileExpr)) + , Condition(std::move(condition)) , InputIsContent(inputIsContent) + , PolicyStatusCMP0070(policyStatusCMP0070) { } @@ -36,7 +37,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; } @@ -51,10 +52,16 @@ void cmGeneratorExpressionEvaluationFile::Generate( } } - const std::string outputFileName = this->OutputFileExpr->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, CM_NULLPTR, CM_NULLPTR, CM_NULLPTR, lang); + lg, config, false, nullptr, nullptr, nullptr, lang); + + if (cmSystemTools::FileIsFullPath(outputFileName)) { + outputFileName = cmSystemTools::CollapseFullPath(outputFileName); + } else { + outputFileName = this->FixRelativePath(outputFileName, PathForOutput, lg); + } std::map::iterator it = outputFiles.find(outputFileName); @@ -92,10 +99,9 @@ void cmGeneratorExpressionEvaluationFile::CreateOutputFile( cmGlobalGenerator* gg = lg->GetGlobalGenerator(); gg->GetEnabledLanguages(enabledLanguages); - for (std::vector::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); + lg, config, false, nullptr, nullptr, nullptr, le); cmSourceFile* sf = lg->GetMakefile()->GetOrCreateSource(name); sf->SetProperty("GENERATED", "1"); @@ -111,12 +117,18 @@ 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."; + e << "Evaluation file \"" << inputFileName << "\" cannot be read."; lg->IssueMessage(cmake::FATAL_ERROR, e.str()); return; } @@ -132,7 +144,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg) cmListFileBacktrace lfbt = this->OutputFileExpr->GetBacktrace(); cmGeneratorExpression contentGE(lfbt); - CM_AUTO_PTR inputExpression = + std::unique_ptr inputExpression = contentGE.Parse(inputContent); std::map outputFiles; @@ -148,14 +160,66 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg) cmGlobalGenerator* gg = lg->GetGlobalGenerator(); gg->GetEnabledLanguages(enabledLanguages); - for (std::vector::const_iterator le = enabledLanguages.begin(); - le != enabledLanguages.end(); ++le) { - for (std::vector::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(cmake::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..2a790697f 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.h +++ b/Source/cmGeneratorExpressionEvaluationFile.h @@ -6,11 +6,12 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include // IWYU pragma: keep #include #include #include "cmGeneratorExpression.h" -#include "cm_auto_ptr.hxx" +#include "cmPolicies.h" #include "cm_sys_stat.h" class cmLocalGenerator; @@ -20,8 +21,9 @@ class cmGeneratorExpressionEvaluationFile public: cmGeneratorExpressionEvaluationFile( const std::string& input, - CM_AUTO_PTR outputFileExpr, - CM_AUTO_PTR condition, bool inputIsContent); + std::unique_ptr outputFileExpr, + std::unique_ptr condition, + bool inputIsContent, cmPolicies::PolicyStatus policyStatusCMP0070); void Generate(cmLocalGenerator* lg); @@ -35,12 +37,21 @@ private: cmCompiledGeneratorExpression* inputExpression, std::map& 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 OutputFileExpr; - const CM_AUTO_PTR Condition; + const std::unique_ptr OutputFileExpr; + const std::unique_ptr Condition; std::vector Files; const bool InputIsContent; + cmPolicies::PolicyStatus PolicyStatusCMP0070; }; #endif diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 6ce4a8e72..c73d48601 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -25,13 +25,13 @@ std::string GeneratorExpressionContent::ProcessArbitraryContent( const cmGeneratorExpressionNode* node, const std::string& identifier, cmGeneratorExpressionContext* context, cmGeneratorExpressionDAGChecker* dagChecker, - std::vector >::const_iterator + std::vector>::const_iterator pit) const { std::string result; const std::vector< - std::vector >::const_iterator pend = + std::vector>::const_iterator pend = this->ParamChildren.end(); for (; pit != pend; ++pit) { std::vector::const_iterator it = @@ -122,10 +122,10 @@ std::string GeneratorExpressionContent::EvaluateParameters( { const int numExpected = node->NumExpectedParameters(); { - std::vector >::const_iterator + std::vector>::const_iterator pit = this->ParamChildren.begin(); const std::vector< - std::vector >::const_iterator pend = + std::vector>::const_iterator pend = this->ParamChildren.end(); const bool acceptsArbitraryContent = node->AcceptsArbitraryContentParameter(); @@ -153,7 +153,7 @@ std::string GeneratorExpressionContent::EvaluateParameters( } if ((numExpected > cmGeneratorExpressionNode::DynamicParameters && - (unsigned int)numExpected != parameters.size())) { + static_cast(numExpected) != parameters.size())) { if (numExpected == 0) { reportError(context, this->GetOriginalExpression(), "$<" + identifier + "> expression requires no parameters."); @@ -188,5 +188,5 @@ GeneratorExpressionContent::~GeneratorExpressionContent() { cmDeleteAll(this->IdentifierChildren); std::for_each(this->ParamChildren.begin(), this->ParamChildren.end(), - cmDeleteAll >); + cmDeleteAll>); } diff --git a/Source/cmGeneratorExpressionEvaluator.h b/Source/cmGeneratorExpressionEvaluator.h index a0a826ac6..92dac79ea 100644 --- a/Source/cmGeneratorExpressionEvaluator.h +++ b/Source/cmGeneratorExpressionEvaluator.h @@ -3,7 +3,7 @@ #ifndef cmGeneratorExpressionEvaluator_h #define cmGeneratorExpressionEvaluator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -42,12 +42,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; } @@ -71,23 +71,23 @@ struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator } void SetParameters( - std::vector > const& + std::vector> const& parameters) { this->ParamChildren = 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 +100,12 @@ private: const cmGeneratorExpressionNode* node, const std::string& identifier, cmGeneratorExpressionContext* context, cmGeneratorExpressionDAGChecker* dagChecker, - std::vector >::const_iterator + std::vector>::const_iterator pit) const; private: std::vector IdentifierChildren; - std::vector > ParamChildren; + std::vector> ParamChildren; const char* StartContent; size_t ContentLength; }; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index a57d2a0d8..fea20ba87 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -17,16 +17,15 @@ #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" -#include "cmConfigure.h" #include "cmsys/RegularExpression.hxx" #include "cmsys/String.h" #include #include #include #include +#include // IWYU pragma: keep #include #include #include @@ -40,7 +39,7 @@ std::string cmGeneratorExpressionNode::EvaluateDependentExpression( cmGeneratorExpressionDAGChecker* dagChecker) { cmGeneratorExpression ge(context->Backtrace); - CM_AUTO_PTR cge = ge.Parse(prop); + std::unique_ptr cge = ge.Parse(prop); cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem); std::string result = cge->Evaluate(lg, context->Config, context->Quiet, headTarget, @@ -58,15 +57,15 @@ static const struct ZeroNode : public cmGeneratorExpressionNode { ZeroNode() {} - 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& /*parameters*/, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& /*parameters*/, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return std::string(); } @@ -76,13 +75,13 @@ static const struct OneNode : public cmGeneratorExpressionNode { OneNode() {} - bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; } + bool AcceptsArbitraryContentParameter() const override { return true; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return parameters.front(); } @@ -129,11 +128,11 @@ static const struct NotNode : public cmGeneratorExpressionNode { NotNode() {} - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { if (*parameters.begin() != "0" && *parameters.begin() != "1") { reportError( @@ -149,13 +148,13 @@ static const struct BoolNode : public cmGeneratorExpressionNode { BoolNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 1; } + int NumExpectedParameters() const override { return 1; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return !cmSystemTools::IsOff(parameters.begin()->c_str()) ? "1" : "0"; } @@ -165,12 +164,12 @@ static const struct IfNode : public cmGeneratorExpressionNode { IfNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 3; } + int NumExpectedParameters() const override { return 3; } std::string Evaluate(const std::vector& parameters, cmGeneratorExpressionContext* context, const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker*) const CM_OVERRIDE + cmGeneratorExpressionDAGChecker*) const override { if (parameters[0] != "1" && parameters[0] != "0") { reportError(context, content->GetOriginalExpression(), @@ -186,13 +185,13 @@ static const struct StrEqualNode : public cmGeneratorExpressionNode { StrEqualNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 2; } + int NumExpectedParameters() const override { return 2; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return *parameters.begin() == parameters[1] ? "1" : "0"; } @@ -202,13 +201,13 @@ static const struct EqualNode : public cmGeneratorExpressionNode { EqualNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 2; } + int NumExpectedParameters() const override { return 2; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { char* pEnd; @@ -280,13 +279,13 @@ static const struct LowerCaseNode : public cmGeneratorExpressionNode { LowerCaseNode() {} - bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; } + bool AcceptsArbitraryContentParameter() const override { return true; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return cmSystemTools::LowerCase(parameters.front()); } @@ -296,13 +295,13 @@ static const struct UpperCaseNode : public cmGeneratorExpressionNode { UpperCaseNode() {} - bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; } + bool AcceptsArbitraryContentParameter() const override { return true; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return cmSystemTools::UpperCase(parameters.front()); } @@ -312,13 +311,13 @@ static const struct MakeCIdentifierNode : public cmGeneratorExpressionNode { MakeCIdentifierNode() {} - bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; } + bool AcceptsArbitraryContentParameter() const override { return true; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return cmSystemTools::MakeCidentifier(parameters.front()); } @@ -328,13 +327,13 @@ static const struct Angle_RNode : public cmGeneratorExpressionNode { Angle_RNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 0; } + int NumExpectedParameters() const override { return 0; } - std::string Evaluate(const std::vector& /*parameters*/, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& /*parameters*/, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return ">"; } @@ -344,13 +343,13 @@ static const struct CommaNode : public cmGeneratorExpressionNode { CommaNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 0; } + int NumExpectedParameters() const override { return 0; } - std::string Evaluate(const std::vector& /*parameters*/, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& /*parameters*/, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return ","; } @@ -360,13 +359,13 @@ static const struct SemicolonNode : public cmGeneratorExpressionNode { SemicolonNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 0; } + int NumExpectedParameters() const override { return 0; } - std::string Evaluate(const std::vector& /*parameters*/, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& /*parameters*/, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return ";"; } @@ -376,7 +375,7 @@ struct CompilerIdNode : public cmGeneratorExpressionNode { CompilerIdNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return OneOrZeroParameters; } std::string EvaluateWithLanguage(const std::vector& parameters, cmGeneratorExpressionContext* context, @@ -428,11 +427,11 @@ static const struct CCompilerIdNode : public CompilerIdNode { CCompilerIdNode() {} - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override { if (!context->HeadTarget) { reportError( @@ -450,11 +449,11 @@ static const struct CXXCompilerIdNode : public CompilerIdNode { CXXCompilerIdNode() {} - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override { if (!context->HeadTarget) { reportError( @@ -472,7 +471,7 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode { CompilerVersionNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return OneOrZeroParameters; } std::string EvaluateWithLanguage(const std::vector& parameters, cmGeneratorExpressionContext* context, @@ -509,11 +508,11 @@ static const struct CCompilerVersionNode : public CompilerVersionNode { CCompilerVersionNode() {} - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override { if (!context->HeadTarget) { reportError( @@ -531,11 +530,11 @@ static const struct CxxCompilerVersionNode : public CompilerVersionNode { CxxCompilerVersionNode() {} - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override { if (!context->HeadTarget) { reportError( @@ -553,13 +552,13 @@ struct PlatformIdNode : public cmGeneratorExpressionNode { PlatformIdNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return OneOrZeroParameters; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { const char* platformId = context->LG->GetMakefile()->GetSafeDefinition("CMAKE_SYSTEM_NAME"); @@ -582,13 +581,13 @@ static const struct VersionGreaterNode : public cmGeneratorExpressionNode { VersionGreaterNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 2; } + int NumExpectedParameters() const override { return 2; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER, parameters.front().c_str(), @@ -602,13 +601,13 @@ static const struct VersionGreaterEqNode : public cmGeneratorExpressionNode { VersionGreaterEqNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 2; } + int NumExpectedParameters() const override { return 2; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL, parameters.front().c_str(), @@ -622,13 +621,13 @@ static const struct VersionLessNode : public cmGeneratorExpressionNode { VersionLessNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 2; } + int NumExpectedParameters() const override { return 2; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, parameters.front().c_str(), @@ -642,13 +641,13 @@ static const struct VersionLessEqNode : public cmGeneratorExpressionNode { VersionLessEqNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 2; } + int NumExpectedParameters() const override { return 2; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS_EQUAL, parameters.front().c_str(), @@ -662,13 +661,13 @@ static const struct VersionEqualNode : public cmGeneratorExpressionNode { VersionEqualNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 2; } + int NumExpectedParameters() const override { return 2; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL, parameters.front().c_str(), @@ -682,11 +681,11 @@ static const struct LinkOnlyNode : public cmGeneratorExpressionNode { LinkOnlyNode() {} - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override { if (!dagChecker) { reportError(context, content->GetOriginalExpression(), @@ -704,13 +703,13 @@ static const struct ConfigurationNode : public cmGeneratorExpressionNode { ConfigurationNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 0; } + int NumExpectedParameters() const override { return 0; } - std::string Evaluate(const std::vector& /*parameters*/, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& /*parameters*/, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { context->HadContextSensitiveCondition = true; return context->Config; @@ -721,17 +720,16 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode { ConfigurationTestNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return OneOrZeroParameters; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& 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())) { @@ -750,8 +748,8 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode } 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)) { @@ -781,15 +779,15 @@ static const struct JoinNode : public cmGeneratorExpressionNode { JoinNode() {} - 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& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* /*context*/, + const GeneratorExpressionContent* /*content*/, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { std::vector list; cmSystemTools::ExpandListArgument(parameters.front(), list); @@ -801,19 +799,19 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode { CompileLanguageNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return OneOrZeroParameters; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override { if (context->Language.empty()) { reportError( context, content->GetOriginalExpression(), "$ 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(); } @@ -864,7 +862,7 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode #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 +877,12 @@ std::string getLinkedTargetsContent( std::string linkedTargetsContent; std::string sep; std::string depString; - for (typename std::vector::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->GetName() + "," + + if (l.Target && l.Target != target) { + depString += sep + "$GetName() + "," + interfacePropertyName + ">"; sep = ";"; } @@ -906,13 +903,13 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode TargetPropertyNode() {} // 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& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagCheckerParent) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagCheckerParent) const override { if (parameters.size() != 1 && parameters.size() != 2) { reportError( @@ -1199,21 +1196,21 @@ static const struct TargetNameNode : public cmGeneratorExpressionNode { TargetNameNode() {} - 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& parameters, - cmGeneratorExpressionContext* /*context*/, - const GeneratorExpressionContent* /*content*/, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& 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; @@ -1221,11 +1218,11 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode { TargetObjectsNode() {} - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { std::string tgtName = parameters.front(); cmGeneratorTarget* gt = context->LG->FindGeneratorTargetToUse(tgtName); @@ -1260,8 +1257,8 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode std::vector 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 +1280,15 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode context->HadContextSensitiveCondition = true; } - for (std::vector::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::iterator oi = objects.begin(); - oi != objects.end(); ++oi) { - mf->AddTargetObject(tgtName, *oi); + for (std::string& o : objects) { + mf->AddTargetObject(tgtName, o); } return cmJoin(objects, ";"); @@ -1304,13 +1299,13 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode { CompileFeaturesNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return OneOrMoreParameters; } + int NumExpectedParameters() const override { return OneOrMoreParameters; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override { cmGeneratorTarget const* target = context->HeadTarget; if (!target) { @@ -1322,21 +1317,20 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode } context->HadHeadSensitiveCondition = true; - typedef std::map > LangMap; + typedef std::map> LangMap; static LangMap availableFeatures; LangMap testedFeatures; - for (std::vector::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 +1346,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 const& langAvailable = - availableFeatures[lit->first]; + availableFeatures[lit.first]; const char* standardDefault = context->LG->GetMakefile()->GetDefinition( - "CMAKE_" + lit->first + "_STANDARD_DEFAULT"); - for (std::vector::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 +1362,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 +1381,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 }; @@ -1432,13 +1424,13 @@ static const struct TargetPolicyNode : public cmGeneratorExpressionNode { TargetPolicyNode() {} - int NumExpectedParameters() const CM_OVERRIDE { return 1; } + int NumExpectedParameters() const override { return 1; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { if (!context->HeadTarget) { reportError( @@ -1493,14 +1485,14 @@ static const struct InstallPrefixNode : public cmGeneratorExpressionNode { InstallPrefixNode() {} - 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& /*parameters*/, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& /*parameters*/, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { reportError(context, content->GetOriginalExpression(), "INSTALL_PREFIX is a marker for install(EXPORT) only. It " @@ -1713,13 +1705,13 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode { TargetFilesystemArtifact() {} - int NumExpectedParameters() const CM_OVERRIDE { return 1; } + int NumExpectedParameters() const override { return 1; } - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override { // Lookup the referenced target. std::string name = *parameters.begin(); @@ -1795,11 +1787,11 @@ static const struct ShellPathNode : public cmGeneratorExpressionNode { ShellPathNode() {} - std::string Evaluate(const std::vector& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* /*dagChecker*/) const - CM_OVERRIDE + std::string Evaluate( + const std::vector& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { if (!cmSystemTools::FileIsFullPath(parameters.front())) { reportError(context, content->GetOriginalExpression(), @@ -1873,7 +1865,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode( } NodeMap::const_iterator i = nodeMap.find(identifier); if (i == nodeMap.end()) { - return CM_NULLPTR; + return nullptr; } return i->second; } diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx index c33349a63..278de0444 100644 --- a/Source/cmGeneratorExpressionParser.cxx +++ b/Source/cmGeneratorExpressionParser.cxx @@ -97,7 +97,7 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression( return; } - std::vector > parameters; + std::vector> parameters; std::vector::const_iterator> commaTokens; std::vector::const_iterator colonToken; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index c9924f670..103d0340e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -7,11 +7,13 @@ #include #include #include +#include // IWYU pragma: keep #include #include #include #include #include +#include #include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" @@ -31,8 +33,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; @@ -64,13 +64,13 @@ class cmGeneratorTarget::TargetPropertyEntry static cmLinkImplItem NoLinkImplItem; public: - TargetPropertyEntry(CM_AUTO_PTR cge, + TargetPropertyEntry(std::unique_ptr cge, cmLinkImplItem const& item = NoLinkImplItem) - : ge(cge) + : ge(std::move(cge)) , LinkImplItem(item) { } - const CM_AUTO_PTR ge; + const std::unique_ptr ge; cmLinkImplItem const& LinkImplItem; }; cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem; @@ -84,9 +84,10 @@ void CreatePropertyGeneratorExpressions( for (std::vector::const_iterator it = entries.begin(); it != entries.end(); ++it, ++btIt) { cmGeneratorExpression ge(*btIt); - CM_AUTO_PTR cge = ge.Parse(*it); + std::unique_ptr cge = ge.Parse(*it); cge->SetEvaluateForBuildsystem(evaluateForBuildsystem); - items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge)); + items.push_back( + new cmGeneratorTarget::TargetPropertyEntry(std::move(cge))); } } @@ -150,11 +151,8 @@ cmGeneratorTarget::~cmGeneratorTarget() const char* cmGeneratorTarget::GetSourcesProperty() const { std::vector values; - for (std::vector::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->ge->GetInput()); } static std::string value; value.clear(); @@ -204,14 +202,14 @@ 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); } @@ -299,9 +297,8 @@ std::string cmGeneratorTarget::GetOutputName( props.push_back("OUTPUT_NAME"); std::string outName; - for (std::vector::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,7 +310,7 @@ std::string cmGeneratorTarget::GetOutputName( // Now evaluate genex and update the previously-prepared map entry. cmGeneratorExpression ge; - CM_AUTO_PTR cge = ge.Parse(outName); + std::unique_ptr 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 @@ -326,15 +323,21 @@ std::string cmGeneratorTarget::GetOutputName( return i->second; } +void cmGeneratorTarget::ClearSourcesCache() +{ + this->KindedSourcesMap.clear(); + this->LinkImplementationLanguageIsContextDependent = true; + this->Objects.clear(); +} + void cmGeneratorTarget::AddSourceCommon(const std::string& src) { cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); cmGeneratorExpression ge(lfbt); - CM_AUTO_PTR cge = ge.Parse(src); + std::unique_ptr cge = ge.Parse(src); cge->SetEvaluateForBuildsystem(true); - this->SourceEntries.push_back(new TargetPropertyEntry(cge)); - this->KindedSourcesMap.clear(); - this->LinkImplementationLanguageIsContextDependent = true; + this->SourceEntries.push_back(new TargetPropertyEntry(std::move(cge))); + this->ClearSourcesCache(); } void cmGeneratorTarget::AddSource(const std::string& src) @@ -357,13 +360,14 @@ void cmGeneratorTarget::AddIncludeDirectory(const std::string& src, this->Target->InsertInclude(src, this->Makefile->GetBacktrace(), before); cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); cmGeneratorExpression ge(lfbt); - CM_AUTO_PTR cge = ge.Parse(src); + std::unique_ptr cge = ge.Parse(src); cge->SetEvaluateForBuildsystem(true); // Insert before begin/end std::vector::iterator pos = before ? this->IncludeDirectoriesEntries.begin() : this->IncludeDirectoriesEntries.end(); - this->IncludeDirectoriesEntries.insert(pos, new TargetPropertyEntry(cge)); + this->IncludeDirectoriesEntries.insert( + pos, new TargetPropertyEntry(std::move(cge))); } std::vector const* cmGeneratorTarget::GetSourceDepends( @@ -373,7 +377,7 @@ std::vector const* cmGeneratorTarget::GetSourceDepends( if (i != this->SourceDepends.end()) { return &i->second.Depends; } - return CM_NULLPTR; + return nullptr; } static void handleSystemIncludesDep( @@ -408,10 +412,9 @@ static void handleSystemIncludesDep( #define IMPLEMENT_VISIT(KIND) \ { \ KindedSources const& kinded = this->GetKindedSources(config); \ - for (std::vector::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); \ } \ } \ } @@ -426,9 +429,8 @@ void cmGeneratorTarget::GetObjectSources( return; } - for (std::vector::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); @@ -445,10 +447,9 @@ void cmGeneratorTarget::ComputeObjectMapping() if (configs.empty()) { configs.push_back(""); } - for (std::vector::const_iterator ci = configs.begin(); - ci != configs.end(); ++ci) { + for (std::string const& c : configs) { std::vector sourceFiles; - this->GetObjectSources(sourceFiles, *ci); + this->GetObjectSources(sourceFiles, c); } } @@ -511,7 +512,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 + @@ -553,7 +554,7 @@ const char* cmGeneratorTarget::GetCustomObjectExtension() const extension = ".ptx"; return extension.c_str(); } - return CM_NULLPTR; + return nullptr; } void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf) @@ -649,11 +650,10 @@ std::set const& cmGeneratorTarget::GetUtilityItems() const if (!this->UtilityItemsDone) { this->UtilityItemsDone = true; std::set const& utilities = this->GetUtilities(); - for (std::set::const_iterator i = utilities.begin(); - i != utilities.end(); ++i) { + for (std::string const& i : utilities) { cmGeneratorTarget* gt = - this->LocalGenerator->FindGeneratorTargetToUse(*i); - this->UtilityItems.insert(cmLinkItem(*i, gt)); + this->LocalGenerator->FindGeneratorTargetToUse(i); + this->UtilityItems.insert(cmLinkItem(i, gt)); } } return this->UtilityItems; @@ -743,34 +743,29 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory( config_upper = cmSystemTools::UpperCase(config); } - typedef std::map > IncludeCacheType; + typedef std::map> 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->GetName(), "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr); bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED"); std::vector result; - for (std::set::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), result); } std::vector const& deps = this->GetLinkImplementationClosure(config); - for (std::vector::const_iterator - li = deps.begin(), - le = deps.end(); - li != le; ++li) { - handleSystemIncludesDep(this->LocalGenerator, *li, config, this, + for (cmGeneratorTarget const* dep : deps) { + handleSystemIncludesDep(this->LocalGenerator, dep, config, this, &dagChecker, result, excludeImported); } @@ -798,17 +793,14 @@ static void AddInterfaceEntries( { if (cmLinkImplementationLibraries const* impl = thisTarget->GetLinkImplementationLibraries(config)) { - for (std::vector::const_iterator - it = impl->Libraries.begin(), - end = impl->Libraries.end(); - it != end; ++it) { - if (it->Target) { - std::string genex = "$"; - cmGeneratorExpression ge(it->Backtrace); - CM_AUTO_PTR cge = ge.Parse(genex); + for (cmLinkImplItem const& lib : impl->Libraries) { + if (lib.Target) { + std::string genex = "$"; + cmGeneratorExpression ge(lib.Backtrace); + std::unique_ptr cge = ge.Parse(genex); cge->SetEvaluateForBuildsystem(true); entries.push_back( - new cmGeneratorTarget::TargetPropertyEntry(cge, *it)); + new cmGeneratorTarget::TargetPropertyEntry(std::move(cge), lib)); } } } @@ -817,7 +809,7 @@ static void AddInterfaceEntries( static bool processSources( cmGeneratorTarget const* tgt, const std::vector& entries, - std::vector& srcs, CM_UNORDERED_SET& uniqueSrcs, + std::vector& srcs, std::unordered_set& uniqueSrcs, cmGeneratorExpressionDAGChecker* dagChecker, std::string const& config, bool debugSources) { @@ -825,25 +817,20 @@ static bool processSources( bool contextDependent = false; - for (std::vector::const_iterator - it = entries.begin(), - end = entries.end(); - it != end; ++it) { - cmLinkImplItem const& item = (*it)->LinkImplItem; + for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) { + cmLinkImplItem const& item = entry->LinkImplItem; std::string const& targetName = item; std::vector entrySources; cmSystemTools::ExpandListArgument( - (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, tgt, + entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, tgt, dagChecker), entrySources); - if ((*it)->ge->GetHadContextSensitiveCondition()) { + if (entry->ge->GetHadContextSensitiveCondition()) { contextDependent = true; } - for (std::vector::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); @@ -874,10 +861,7 @@ static bool processSources( src = fullPath; } std::string usedSources; - for (std::vector::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); if (debugSources) { @@ -889,7 +873,7 @@ static bool processSources( tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage( cmake::LOG, std::string("Used sources for target ") + tgt->GetName() + ":\n" + usedSources, - (*it)->ge->GetBacktrace()); + entry->ge->GetBacktrace()); } } return contextDependent; @@ -908,19 +892,15 @@ void cmGeneratorTarget::GetSourceFiles(std::vector& 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 items; cmSystemTools::ExpandListArgument(entry, items); - for (std::vector::const_iterator li = items.begin(); - li != items.end(); ++li) { - if (cmHasLiteralPrefix(*li, "$size() - 1] == '>') { + for (std::string const& item : items) { + if (cmHasLiteralPrefix(item, "$') { continue; } - files.push_back(*li); + files.push_back(item); } } return; @@ -942,9 +922,9 @@ void cmGeneratorTarget::GetSourceFiles(std::vector& files, } cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), "SOURCES", - CM_NULLPTR, CM_NULLPTR); + nullptr, nullptr); - CM_UNORDERED_SET uniqueSrcs; + std::unordered_set uniqueSrcs; bool contextDependentDirectSources = processSources(this, this->SourceEntries, files, uniqueSrcs, &dagChecker, config, debugSources); @@ -981,9 +961,8 @@ void cmGeneratorTarget::GetSourceFiles(std::vector& files, std::vector srcs; this->GetSourceFiles(srcs, config); std::set emitted; - for (std::vector::const_iterator i = srcs.begin(); - i != srcs.end(); ++i) { - cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i); + for (std::string const& s : srcs) { + cmSourceFile* sf = this->Makefile->GetOrCreateSource(s); if (emitted.insert(sf).second) { files.push_back(sf); } @@ -993,9 +972,8 @@ void cmGeneratorTarget::GetSourceFiles(std::vector& files, KindedSources const& kinded = this->GetKindedSources(config); files.reserve(kinded.Sources.size()); - for (std::vector::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); } } @@ -1004,10 +982,9 @@ void cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries( { KindedSources const& kinded = this->GetKindedSources(config); files.reserve(kinded.Sources.size()); - for (std::vector::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->GetObjectLibrary().empty()) { + files.push_back(si.Source); } } } @@ -1056,10 +1033,9 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files, std::vector badObjLib; std::set emitted; - for (std::vector::const_iterator i = srcs.begin(); - i != srcs.end(); ++i) { + for (std::string const& s : srcs) { // Create each source at most once. - cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i); + cmSourceFile* sf = this->Makefile->GetOrCreateSource(s); if (!emitted.insert(sf).second) { continue; } @@ -1132,9 +1108,8 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files, if (!badObjLib.empty()) { std::ostringstream e; e << "OBJECT library \"" << this->GetName() << "\" contains:\n"; - for (std::vector::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."; @@ -1161,18 +1136,16 @@ void cmGeneratorTarget::ComputeAllConfigSources() const for (size_t ci = 0; ci < configs.size(); ++ci) { KindedSources const& sources = this->GetKindedSources(configs[ci]); - for (std::vector::const_iterator si = - sources.Sources.begin(); - si != sources.Sources.end(); ++si) { + for (SourceAndKind const& src : sources.Sources) { std::map::iterator mi = - index.find(si->Source); + index.find(src.Source); if (mi == index.end()) { AllConfigSource acs; - acs.Source = si->Source; - acs.Kind = si->Kind; + acs.Source = src.Source; + acs.Kind = src.Kind; this->AllConfigSources.push_back(acs); std::map::value_type entry( - si->Source, this->AllConfigSources.size() - 1); + src.Source, this->AllConfigSources.size() - 1); mi = index.insert(entry).first; } this->AllConfigSources[mi->second].Configs.push_back(ci); @@ -1714,7 +1687,7 @@ const char* cmGeneratorTarget::GetExportMacro() const } return this->ExportMacro.c_str(); } - return CM_NULLPTR; + return nullptr; } class cmTargetCollectLinkLanguages @@ -1722,7 +1695,7 @@ class cmTargetCollectLinkLanguages public: cmTargetCollectLinkLanguages(cmGeneratorTarget const* target, const std::string& config, - CM_UNORDERED_SET& languages, + std::unordered_set& languages, cmGeneratorTarget const* head) : Config(config) , Languages(languages) @@ -1775,21 +1748,18 @@ public: return; } - for (std::vector::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::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& Languages; + std::unordered_set& Languages; cmGeneratorTarget const* HeadTarget; const cmGeneratorTarget* Target; std::set Visited; @@ -1844,9 +1814,8 @@ public: e << "Target " << this->Target->GetName() << " contains multiple languages with the highest linker preference" << " (" << this->Preference << "):\n"; - for (std::set::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(); @@ -1861,26 +1830,22 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config, LinkClosure& lc) const { // Get languages built in this target. - CM_UNORDERED_SET languages; + std::unordered_set languages; cmLinkImplementation const* impl = this->GetLinkImplementation(config); assert(impl); - for (std::vector::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::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::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 +1858,16 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config, cmTargetSelectLinker tsl(this); // First select from the languages compiled directly in this target. - for (std::vector::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::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 +1936,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) { @@ -1982,7 +1945,7 @@ cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo( msg += " which has type "; msg += cmState::GetTargetTypeName(this->GetType()); this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg); - return CM_NULLPTR; + return nullptr; } // Lookup/compute/cache the compile information for this configuration. @@ -2008,7 +1971,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. @@ -2059,7 +2022,7 @@ void cmGeneratorTarget::GetAutoUicOptions(std::vector& result, cmGeneratorExpression ge; cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "AUTOUIC_OPTIONS", CM_NULLPTR, CM_NULLPTR); + this->GetName(), "AUTOUIC_OPTIONS", nullptr, nullptr); cmSystemTools::ExpandListArgument( ge.Parse(prop)->Evaluate(this->LocalGenerator, config, false, this, &dagChecker), @@ -2076,10 +2039,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::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 +2058,8 @@ cmGeneratorTarget::GetLinkImplementationClosure( cmLinkImplementationLibraries const* impl = this->GetLinkImplementationLibraries(config); - for (std::vector::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,7 +2103,7 @@ 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) { @@ -2154,13 +2113,10 @@ cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target) configs.push_back(""); } std::set emitted; - for (std::vector::const_iterator ci = configs.begin(); - ci != configs.end(); ++ci) { + for (std::string const& c : configs) { std::vector sources; - this->GeneratorTarget->GetSourceFiles(sources, *ci); - for (std::vector::const_iterator si = sources.begin(); - si != sources.end(); ++si) { - cmSourceFile* sf = *si; + this->GeneratorTarget->GetSourceFiles(sources, c); + for (cmSourceFile* sf : sources) { const std::set tgts = this->GlobalGenerator->GetFilenameTargetDepends(sf); if (tgts.find(this->GeneratorTarget) != tgts.end()) { @@ -2199,10 +2155,9 @@ void cmTargetTraceDependencies::Trace() if (const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS")) { std::vector objDeps; cmSystemTools::ExpandListArgument(additionalDeps, objDeps); - for (std::vector::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); @@ -2219,7 +2174,7 @@ void cmTargetTraceDependencies::Trace() this->CheckCustomCommand(*cc); } } - this->CurrentEntry = CM_NULLPTR; + this->CurrentEntry = nullptr; this->GeneratorTarget->AddTracedSources(this->NewSources); } @@ -2255,9 +2210,8 @@ void cmTargetTraceDependencies::FollowName(std::string const& name) void cmTargetTraceDependencies::FollowNames( std::vector const& names) { - for (std::vector::const_iterator i = names.begin(); - i != names.end(); ++i) { - this->FollowName(*i); + for (std::string const& name : names) { + this->FollowName(name); } } @@ -2317,9 +2271,8 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc) // Add target-level dependencies referenced by generator expressions. std::set 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.begin(); // Check for a target with this name. if (cmGeneratorTarget* t = this->LocalGenerator->FindGeneratorTargetToUse(command)) { @@ -2333,18 +2286,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 cge = ge.Parse(*cli); + for (std::string const& cl : cCmdLine) { + const std::unique_ptr cge = ge.Parse(cl); cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), "", true); std::set geTargets = cge->GetTargets(); targets.insert(geTargets.begin(), geTargets.end()); } } - for (std::set::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. @@ -2354,9 +2305,8 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc) if (configs.empty()) { configs.push_back(""); } - for (std::vector::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 +2319,7 @@ void cmTargetTraceDependencies::FollowCommandDepends( const std::vector& depends = ccg.GetDepends(); - for (std::vector::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 +2333,8 @@ void cmTargetTraceDependencies::FollowCommandDepends( void cmTargetTraceDependencies::CheckCustomCommands( const std::vector& commands) { - for (std::vector::const_iterator cli = commands.begin(); - cli != commands.end(); ++cli) { - this->CheckCustomCommand(*cli); + for (cmCustomCommand const& command : commands) { + this->CheckCustomCommand(command); } } @@ -2418,7 +2365,7 @@ std::string cmGeneratorTarget::GetCompilePDBDirectory( void cmGeneratorTarget::GetAppleArchs(const std::string& config, std::vector& archVec) const { - const char* archs = CM_NULLPTR; + const char* archs = nullptr; if (!config.empty()) { std::string defVarName = "OSX_ARCHITECTURES_"; defVarName += cmSystemTools::UpperCase(config); @@ -2471,28 +2418,24 @@ static void processIncludeDirectories( cmGeneratorTarget const* tgt, const std::vector& entries, std::vector& includes, - CM_UNORDERED_SET& uniqueIncludes, + std::unordered_set& uniqueIncludes, cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config, bool debugIncludes, const std::string& language) { - for (std::vector::const_iterator - it = entries.begin(), - end = entries.end(); - it != end; ++it) { - cmLinkImplItem const& item = (*it)->LinkImplItem; + for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) { + cmLinkImplItem const& item = entry->LinkImplItem; std::string const& targetName = item; bool const fromImported = item.Target && item.Target->IsImported(); bool const checkCMP0027 = item.FromGenex; std::vector entryIncludes; cmSystemTools::ExpandListArgument( - (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, + entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, dagChecker, language), entryIncludes); std::string usedIncludes; - for (std::vector::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.c_str())) { std::ostringstream e; cmake::MessageType messageType = cmake::FATAL_ERROR; if (checkCMP0027) { @@ -2511,7 +2454,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,7 +2467,7 @@ static void processIncludeDirectories( return; } - if (!cmSystemTools::FileIsFullPath(li->c_str())) { + if (!cmSystemTools::FileIsFullPath(entryInclude.c_str())) { std::ostringstream e; bool noMessage = false; cmake::MessageType messageType = cmake::FATAL_ERROR; @@ -2532,7 +2475,7 @@ static void processIncludeDirectories( /* clang-format off */ e << "Target \"" << targetName << "\" contains relative " "path in its INTERFACE_INCLUDE_DIRECTORIES:\n" - " \"" << *li << "\""; + " \"" << entryInclude << "\""; /* clang-format on */ } else { switch (tgt->GetPolicyStatusCMP0021()) { @@ -2550,7 +2493,7 @@ 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()); @@ -2560,10 +2503,10 @@ static void processIncludeDirectories( } } - if (!cmSystemTools::IsOff(li->c_str())) { - cmSystemTools::ConvertToUnixSlashes(*li); + if (!cmSystemTools::IsOff(entryInclude.c_str())) { + cmSystemTools::ConvertToUnixSlashes(entryInclude); } - std::string inc = *li; + std::string inc = entryInclude; if (uniqueIncludes.insert(inc).second) { includes.push_back(inc); @@ -2576,7 +2519,7 @@ static void processIncludeDirectories( tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage( cmake::LOG, std::string("Used includes for target ") + tgt->GetName() + ":\n" + usedIncludes, - (*it)->ge->GetBacktrace()); + entry->ge->GetBacktrace()); } } } @@ -2585,10 +2528,10 @@ std::vector cmGeneratorTarget::GetIncludeDirectories( const std::string& config, const std::string& lang) const { std::vector includes; - CM_UNORDERED_SET uniqueIncludes; + std::unordered_set uniqueIncludes; cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "INCLUDE_DIRECTORIES", CM_NULLPTR, CM_NULLPTR); + this->GetName(), "INCLUDE_DIRECTORIES", nullptr, nullptr); std::vector debugProperties; const char* debugProp = @@ -2617,10 +2560,8 @@ std::vector cmGeneratorTarget::GetIncludeDirectories( if (this->Makefile->IsOn("APPLE")) { cmLinkImplementationLibraries const* impl = this->GetLinkImplementationLibraries(config); - for (std::vector::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); static cmsys::RegularExpression frameworkCheck( "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$"); @@ -2631,10 +2572,10 @@ std::vector cmGeneratorTarget::GetIncludeDirectories( libDir = frameworkCheck.match(1); cmGeneratorExpression ge; - CM_AUTO_PTR cge = + std::unique_ptr cge = ge.Parse(libDir.c_str()); linkInterfaceIncludeDirectoriesEntries.push_back( - new cmGeneratorTarget::TargetPropertyEntry(cge)); + new cmGeneratorTarget::TargetPropertyEntry(std::move(cge))); } } @@ -2651,24 +2592,18 @@ static void processCompileOptionsInternal( cmGeneratorTarget const* tgt, const std::vector& entries, std::vector& options, - CM_UNORDERED_SET& uniqueOptions, + std::unordered_set& uniqueOptions, cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config, bool debugOptions, const char* logName, std::string const& language) { - for (std::vector::const_iterator - it = entries.begin(), - end = entries.end(); - it != end; ++it) { + for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) { std::vector entryOptions; cmSystemTools::ExpandListArgument( - (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, + entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, dagChecker, language), entryOptions); std::string usedOptions; - for (std::vector::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 (debugOptions) { @@ -2680,7 +2615,7 @@ static void processCompileOptionsInternal( tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage( cmake::LOG, std::string("Used compile ") + logName + std::string(" for target ") + tgt->GetName() + ":\n" + usedOptions, - (*it)->ge->GetBacktrace()); + entry->ge->GetBacktrace()); } } } @@ -2689,7 +2624,7 @@ static void processCompileOptions( cmGeneratorTarget const* tgt, const std::vector& entries, std::vector& options, - CM_UNORDERED_SET& uniqueOptions, + std::unordered_set& uniqueOptions, cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config, bool debugOptions, std::string const& language) { @@ -2702,10 +2637,10 @@ void cmGeneratorTarget::GetCompileOptions(std::vector& result, const std::string& config, const std::string& language) const { - CM_UNORDERED_SET uniqueOptions; + std::unordered_set uniqueOptions; cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "COMPILE_OPTIONS", CM_NULLPTR, CM_NULLPTR); + this->GetName(), "COMPILE_OPTIONS", nullptr, nullptr); std::vector debugProperties; const char* debugProp = @@ -2743,7 +2678,7 @@ static void processCompileFeatures( cmGeneratorTarget const* tgt, const std::vector& entries, std::vector& options, - CM_UNORDERED_SET& uniqueOptions, + std::unordered_set& uniqueOptions, cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config, bool debugOptions) { @@ -2755,10 +2690,10 @@ static void processCompileFeatures( void cmGeneratorTarget::GetCompileFeatures(std::vector& result, const std::string& config) const { - CM_UNORDERED_SET uniqueFeatures; + std::unordered_set uniqueFeatures; cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "COMPILE_FEATURES", CM_NULLPTR, CM_NULLPTR); + this->GetName(), "COMPILE_FEATURES", nullptr, nullptr); std::vector debugProperties; const char* debugProp = @@ -2793,7 +2728,7 @@ static void processCompileDefinitions( cmGeneratorTarget const* tgt, const std::vector& entries, std::vector& options, - CM_UNORDERED_SET& uniqueOptions, + std::unordered_set& uniqueOptions, cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config, bool debugOptions, std::string const& language) { @@ -2806,10 +2741,10 @@ void cmGeneratorTarget::GetCompileDefinitions( std::vector& list, const std::string& config, const std::string& language) const { - CM_UNORDERED_SET uniqueOptions; + std::unordered_set uniqueOptions; cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "COMPILE_DEFINITIONS", CM_NULLPTR, CM_NULLPTR); + this->GetName(), "COMPILE_DEFINITIONS", nullptr, nullptr); std::vector debugProperties; const char* debugProp = @@ -2848,10 +2783,10 @@ void cmGeneratorTarget::GetCompileDefinitions( } case cmPolicies::OLD: { cmGeneratorExpression ge; - CM_AUTO_PTR cge = + std::unique_ptr cge = ge.Parse(configProp); linkInterfaceCompileDefinitionsEntries.push_back( - new cmGeneratorTarget::TargetPropertyEntry(cge)); + new cmGeneratorTarget::TargetPropertyEntry(std::move(cge))); } break; case cmPolicies::NEW: case cmPolicies::REQUIRED_ALWAYS: @@ -2933,9 +2868,8 @@ bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config) const { std::vector features; this->GetCompileFeatures(features, config); - for (std::vector::const_iterator it = features.begin(); - it != features.end(); ++it) { - if (!this->Makefile->AddRequiredTargetFeature(this->Target, *it)) { + for (std::string const& f : features) { + if (!this->Makefile->AddRequiredTargetFeature(this->Target, f)) { return false; } } @@ -3045,8 +2979,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 @@ -3091,7 +3025,7 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName, impName = this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact); } else { - impName = ""; + impName.clear(); } // The program database file name. @@ -3122,7 +3056,7 @@ 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 @@ -3194,9 +3128,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,9 +3141,9 @@ 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; } @@ -3228,7 +3162,7 @@ void cmGeneratorTarget::GetFullNameInternal( const char* targetSuffix = (isImportedLibraryArtifact ? this->GetProperty("IMPORT_SUFFIX") : this->GetProperty("SUFFIX")); - const char* configPostfix = CM_NULLPTR; + const char* configPostfix = nullptr; if (!config.empty()) { std::string configProp = cmSystemTools::UpperCase(config); configProp += "_POSTFIX"; @@ -3236,7 +3170,7 @@ void cmGeneratorTarget::GetFullNameInternal( // Mac application bundles and frameworks have no postfix. if (configPostfix && (this->IsAppBundleOnApple() || this->IsFrameworkOnApple())) { - configPostfix = CM_NULLPTR; + configPostfix = nullptr; } } const char* prefixVar = this->Target->GetPrefixVariableInternal(artifact); @@ -3270,14 +3204,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. @@ -3327,9 +3261,8 @@ std::string cmGeneratorTarget::GetPDBName(const std::string& config) const // PDB_NAME props.push_back("PDB_NAME"); - for (std::vector::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; } @@ -3357,20 +3290,16 @@ void cmGeneratorTarget::GetTargetObjectNames( this->GetObjectSources(objectSources, config); std::map mapping; - for (std::vector::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::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::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); @@ -3433,9 +3362,8 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const if (const char* files = this->GetProperty("PUBLIC_HEADER")) { std::vector relFiles; cmSystemTools::ExpandListArgument(files, relFiles); - for (std::vector::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 +3376,8 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const if (const char* files = this->GetProperty("PRIVATE_HEADER")) { std::vector relFiles; cmSystemTools::ExpandListArgument(files, relFiles); - for (std::vector::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 +3389,8 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const if (const char* files = this->GetProperty("RESOURCE")) { std::vector relFiles; cmSystemTools::ExpandListArgument(files, relFiles); - for (std::vector::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 +3413,9 @@ cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const compat.PropsString.insert("AUTOUIC_OPTIONS"); std::vector const& deps = this->GetLinkImplementationClosure(config); - for (std::vector::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 props; \ cmSystemTools::ExpandListArgument(prop, props); \ compat.Props##x.insert(props.begin(), props.end()); \ @@ -3581,7 +3505,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 +3514,7 @@ const char* getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt, return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config); } assert(false && "Unreachable!"); - return CM_NULLPTR; + return nullptr; } template @@ -3611,13 +3535,12 @@ void checkPropertyConsistency(cmGeneratorTarget const* depender, std::string pdir = cmSystemTools::GetCMakeRoot(); pdir += "/Help/prop_tgt/"; - for (std::vector::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)) { 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 " @@ -3626,9 +3549,9 @@ void checkPropertyConsistency(cmGeneratorTarget const* depender, depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str()); return; } - if (emitted.insert(*pi).second) { - getLinkInterfaceDependentProperty(depender, *pi, config, t, - CM_NULLPTR); + if (emitted.insert(p).second) { + getLinkInterfaceDependentProperty(depender, p, config, t, + nullptr); if (cmSystemTools::GetErrorOccuredFlag()) { return; } @@ -3699,32 +3622,31 @@ void cmGeneratorTarget::CheckPropertyCompatibility( std::set emittedMaxNumbers; static 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(this, li->Target, strBool, emittedBools, - config, BoolType, CM_NULLPTR); + checkPropertyConsistency(this, dep.Target, strBool, emittedBools, + config, BoolType, nullptr); if (cmSystemTools::GetErrorOccuredFlag()) { return; } - checkPropertyConsistency(this, li->Target, strString, + checkPropertyConsistency(this, dep.Target, strString, emittedStrings, config, StringType, - CM_NULLPTR); + nullptr); if (cmSystemTools::GetErrorOccuredFlag()) { return; } - checkPropertyConsistency(this, li->Target, strNumMin, + checkPropertyConsistency(this, dep.Target, strNumMin, emittedMinNumbers, config, - NumberMinType, CM_NULLPTR); + NumberMinType, nullptr); if (cmSystemTools::GetErrorOccuredFlag()) { return; } - checkPropertyConsistency(this, li->Target, strNumMax, + checkPropertyConsistency(this, dep.Target, strNumMax, emittedMaxNumbers, config, - NumberMaxType, CM_NULLPTR); + NumberMaxType, nullptr); if (cmSystemTools::GetErrorOccuredFlag()) { return; } @@ -3858,7 +3780,7 @@ std::pair 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 consistentNumberProperty(const char* lhs, @@ -3867,7 +3789,7 @@ std::pair 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,7 +3822,7 @@ std::pair 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: @@ -3954,16 +3876,13 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt, } std::string interfaceProperty = "INTERFACE_" + p; - for (std::vector::const_iterator li = deps.begin(); - li != deps.end(); ++li) { + 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 propKeys = theTarget->GetPropertyKeys(); const bool ifaceIsSet = std::find(propKeys.begin(), propKeys.end(), @@ -4063,28 +3982,28 @@ bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty( const std::string& p, const std::string& config) const { return checkInterfacePropertyCompatibility(this, p, config, "FALSE", - BoolType, CM_NULLPTR); + BoolType, nullptr); } const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty( const std::string& p, const std::string& config) const { return checkInterfacePropertyCompatibility( - 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( - 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( - this, p, config, "empty", NumberMaxType, CM_NULLPTR); + this, p, config, "empty", NumberMaxType, nullptr); } cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation( @@ -4099,7 +4018,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 +4152,8 @@ std::vector cmGeneratorTarget::GetPropertyKeys() const cmPropertyMap const& propsObject = this->Target->GetProperties(); std::vector 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; } @@ -4275,9 +4193,8 @@ void cmGeneratorTarget::ReportPropertyOrigin( void cmGeneratorTarget::LookupLinkItems(std::vector const& names, std::vector& items) const { - for (std::vector::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; } @@ -4291,15 +4208,15 @@ void cmGeneratorTarget::ExpandLinkItems( std::vector& items, bool& hadHeadSensitiveCondition) const { cmGeneratorExpression ge; - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, CM_NULLPTR, - CM_NULLPTR); + cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, nullptr, + nullptr); // The $ 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 libs; - CM_AUTO_PTR cge = ge.Parse(value); + std::unique_ptr cge = ge.Parse(value); cmSystemTools::ExpandListArgument(cge->Evaluate(this->LocalGenerator, config, false, headTarget, this, &dagChecker), @@ -4320,7 +4237,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 +4261,7 @@ cmLinkInterface const* cmGeneratorTarget::GetLinkInterface( } } - return iface.Exists ? &iface : CM_NULLPTR; + return iface.Exists ? &iface : nullptr; } void cmGeneratorTarget::ComputeLinkInterface( @@ -4357,22 +4274,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 emitted; - for (std::vector::const_iterator li = - iface.Libraries.begin(); - li != iface.Libraries.end(); ++li) { - emitted.insert(*li); + std::unordered_set 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::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 +4349,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 +4372,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 +4407,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. @@ -4504,7 +4417,7 @@ cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo( msg += " which has type "; msg += cmState::GetTargetTypeName(this->GetType()); this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg); - return CM_NULLPTR; + return nullptr; } // Lookup/compute/cache the output information for this configuration. @@ -4537,7 +4450,7 @@ cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo( cmake::FATAL_ERROR, "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.", this->GetBacktrace()); - return CM_NULLPTR; + return nullptr; } return &i->second; } @@ -4552,7 +4465,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 +4474,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 +4486,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 cge = ge.Parse(config_outdir); + std::unique_ptr 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 cge = ge.Parse(outdir); + std::unique_ptr 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 +4543,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 +4553,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_"; @@ -4653,7 +4567,7 @@ bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind, out = config_outdir; // Skip per-configuration subdirectory. - conf = ""; + conf.clear(); } else if (const char* outdir = this->GetProperty(propertyName)) { // Use the user-specified output directory. out = outdir; @@ -4697,7 +4611,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,7 +4654,7 @@ 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->PolicyWarnedCMP0022 = true; @@ -4824,7 +4738,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); @@ -4860,7 +4774,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 +4800,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 +4817,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; @@ -5049,7 +4963,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); @@ -5084,19 +4998,17 @@ bool cmGeneratorTarget::GetConfigCommonSourceFiles( if (configFiles != files) { std::string firstConfigFiles; const char* sep = ""; - for (std::vector::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::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; @@ -5127,17 +5039,13 @@ 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::const_iterator i = rng.begin(); - i != rng.end(); ++i) { - std::string const& entry = *i; - + for (std::string const& entry : rng) { std::vector files; cmSystemTools::ExpandListArgument(entry, files); - for (std::vector::const_iterator li = files.begin(); - li != files.end(); ++li) { - if (cmHasLiteralPrefix(*li, "$size() - 1] == '>') { - std::string objLibName = li->substr(17, li->size() - 18); + for (std::string const& li : files) { + if (cmHasLiteralPrefix(li, "$') { + std::string objLibName = li.substr(17, li.size() - 18); if (cmGeneratorExpression::Find(objLibName) != std::string::npos) { continue; @@ -5203,9 +5111,8 @@ void cmGeneratorTarget::GetLanguages(std::set& languages, { std::vector sourceFiles; this->GetSourceFiles(sourceFiles, config); - for (std::vector::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,27 +5124,21 @@ void cmGeneratorTarget::GetLanguages(std::set& languages, std::vector objectTargets; this->GetObjectLibrariesCMP0026(objectTargets); objectLibraries.reserve(objectTargets.size()); - for (std::vector::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::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); } } } - for (std::vector::const_iterator i = - objectLibraries.begin(); - i != objectLibraries.end(); ++i) { - (*i)->GetLanguages(languages, config); + for (cmGeneratorTarget* objLib : objectLibraries) { + objLib->GetLanguages(languages, config); } } @@ -5281,7 +5182,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. @@ -5322,9 +5223,9 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( le != end; ++le, ++btIt) { std::vector llibs; cmGeneratorExpressionDAGChecker dagChecker( - this->GetName(), "LINK_LIBRARIES", CM_NULLPTR, CM_NULLPTR); + this->GetName(), "LINK_LIBRARIES", nullptr, nullptr); cmGeneratorExpression ge(*btIt); - CM_AUTO_PTR const cge = ge.Parse(*le); + std::unique_ptr const cge = ge.Parse(*le); std::string const evaluated = cge->Evaluate(this->LocalGenerator, config, false, head, &dagChecker); cmSystemTools::ExpandListArgument(evaluated, llibs); @@ -5332,10 +5233,9 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( impl.HadHeadSensitiveCondition = true; } - for (std::vector::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; @@ -5373,10 +5273,9 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( } std::set const& seenProps = cge->GetSeenTargetProperties(); - for (std::set::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,10 +5289,9 @@ 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; } @@ -5415,7 +5313,7 @@ cmGeneratorTarget* cmGeneratorTarget::FindTargetToLink( // within the project. if (tgt && tgt->GetType() == cmStateEnums::EXECUTABLE && !tgt->IsExecutableWithExports()) { - tgt = CM_NULLPTR; + tgt = nullptr; } if (tgt && tgt->GetType() == cmStateEnums::OBJECT_LIBRARY) { @@ -5429,7 +5327,7 @@ cmGeneratorTarget* cmGeneratorTarget::FindTargetToLink( "with the ENABLE_EXPORTS property set."; cmake* cm = this->LocalGenerator->GetCMakeInstance(); cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace()); - tgt = CM_NULLPTR; + tgt = nullptr; } return tgt; diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 52147e319..1ee8a16fb 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" @@ -491,6 +491,11 @@ public: std::string GetOutputName(const std::string& config, cmStateEnums::ArtifactType artifact) 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); void AddTracedSources(std::vector const& srcs); @@ -519,7 +524,7 @@ public: { SourceFileFlags() : Type(SourceFileTypeNormal) - , MacFolder(CM_NULLPTR) + , MacFolder(nullptr) { } SourceFileType Type; @@ -565,7 +570,7 @@ public: /** 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; + const char* newExt = nullptr) const; bool IsExecutableWithExports() const; @@ -656,7 +661,7 @@ private: SourceEntriesType SourceDepends; mutable std::map Objects; std::set ExplicitObjectName; - mutable std::map > SystemIncludesCache; + mutable std::map> SystemIncludesCache; mutable std::string ExportMacro; 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmGetDirectoryPropertyCommand.cxx b/Source/cmGetDirectoryPropertyCommand.cxx index 1005b1543..a8cf6ab9c 100644 --- a/Source/cmGetDirectoryPropertyCommand.cxx +++ b/Source/cmGetDirectoryPropertyCommand.cxx @@ -70,7 +70,7 @@ bool cmGetDirectoryPropertyCommand::InitialPass( return true; } - const char* prop = CM_NULLPTR; + const char* prop = nullptr; if (!i->empty()) { if (*i == "DEFINITIONS") { switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0059)) { 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 #include @@ -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 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..1b358aba8 100644 --- a/Source/cmGetFilenameComponentCommand.cxx +++ b/Source/cmGetFilenameComponentCommand.cxx @@ -60,7 +60,30 @@ 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") { 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index ddecdf621..4494c3e87 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -258,9 +258,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 +333,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 +357,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 #include @@ -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 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx index 0910a5324..ec485aa3e 100644 --- a/Source/cmGetTargetPropertyCommand.cxx +++ b/Source/cmGetTargetPropertyCommand.cxx @@ -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], 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 #include @@ -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 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmGhsMultiGpj.h b/Source/cmGhsMultiGpj.h index 7bc7bfc46..b1eead101 100644 --- a/Source/cmGhsMultiGpj.h +++ b/Source/cmGhsMultiGpj.h @@ -3,7 +3,7 @@ #ifndef cmGhsMultiGpj_h #define cmGhsMultiGpj_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep class cmGeneratedFileStream; diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 7032cd582..a31e415b8 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -363,7 +363,7 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries( this->GeneratorTarget->GetCreateRuleVariable(language, config); bool useWatcomQuote = this->Makefile->IsOn(createRule + "_USE_WATCOM_QUOTE"); - CM_AUTO_PTR linkLineComputer( + std::unique_ptr linkLineComputer( this->GetGlobalGenerator()->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -439,7 +439,7 @@ cmGhsMultiTargetGenerator::GetObjectNames( cmLocalGhsMultiGenerator* const localGhsMultiGenerator, cmGeneratorTarget* const generatorTarget) { - std::map > filenameToSource; + std::map> filenameToSource; std::map sourceToFilename; for (std::vector::const_iterator sf = objectSources->begin(); sf != objectSources->end(); ++sf) { @@ -451,7 +451,7 @@ cmGhsMultiTargetGenerator::GetObjectNames( } std::vector duplicateSources; - for (std::map >::const_iterator + for (std::map>::const_iterator msvSourceI = filenameToSource.begin(); msvSourceI != filenameToSource.end(); ++msvSourceI) { if (msvSourceI->second.size() > 1) { 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..05efff317 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -89,9 +89,9 @@ cmGlobalGenerator::cmGlobalGenerator(cmake* cm) // how long to let try compiles run this->TryCompileTimeout = 0; - 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; @@ -244,15 +244,13 @@ bool cmGlobalGenerator::GenerateImportFile(const std::string& file) bool result = it->second->GenerateImportFile(); if (!this->ConfigureDoneCMP0026AndCMP0024) { - for (std::vector::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; } @@ -383,12 +381,11 @@ void cmGlobalGenerator::EnableLanguage( } std::set cur_languages(languages.begin(), languages.end()); - for (std::set::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."; + e << "Language '" << li << "' is currently being enabled. " + "Recursive call not allowed."; mf->IssueMessage(cmake::FATAL_ERROR, e.str()); cmSystemTools::SetFatalErrorOccured(); return; @@ -397,12 +394,11 @@ void cmGlobalGenerator::EnableLanguage( if (this->TryCompileOuterMakefile) { // In a try-compile we can only enable languages provided by caller. - for (std::vector::const_iterator li = languages.begin(); - li != languages.end(); ++li) { - if (*li == "NONE") { + for (std::string const& li : languages) { + if (li == "NONE") { this->SetLanguageEnabled("NONE", mf); } else { - const char* lang = li->c_str(); + const char* lang = li.c_str(); if (this->LanguagesReady.find(lang) == this->LanguagesReady.end()) { std::ostringstream e; e << "The test project needs language " << lang @@ -451,15 +447,6 @@ 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"); @@ -490,7 +477,6 @@ void cmGlobalGenerator::EnableLanguage( windowsVersionString << osviex.dwMajorVersion << "." << osviex.dwMinorVersion << "." << osviex.dwBuildNumber; - windowsVersionString.str(); mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", windowsVersionString.str().c_str()); #endif @@ -505,6 +491,11 @@ void cmGlobalGenerator::EnableLanguage( } if (readCMakeSystem) { + // Find the native build tool for this generator. + if (!this->FindMakeProgram(mf)) { + return; + } + // Tell the generator about the target system. std::string system = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME"); if (!this->SetSystemName(system, mf)) { @@ -527,6 +518,12 @@ void cmGlobalGenerator::EnableLanguage( } } + // 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"); @@ -542,11 +539,10 @@ void cmGlobalGenerator::EnableLanguage( // load the CMakeDetermine(LANG)Compiler.cmake file to find // the compiler - for (std::vector::const_iterator l = languages.begin(); - l != languages.end(); ++l) { - const char* lang = l->c_str(); + for (std::string const& l : languages) { + const char* lang = l.c_str(); needSetLanguageEnabledMaps[lang] = false; - if (*l == "NONE") { + if (l == "NONE") { this->SetLanguageEnabled("NONE", mf); continue; } @@ -648,10 +644,9 @@ void cmGlobalGenerator::EnableLanguage( } // loop over languages again loading CMake(LANG)Information.cmake // - for (std::vector::const_iterator l = languages.begin(); - l != languages.end(); ++l) { - const char* lang = l->c_str(); - if (*l == "NONE") { + for (std::string const& l : languages) { + const char* lang = l.c_str(); + if (l == "NONE") { this->SetLanguageEnabled("NONE", mf); continue; } @@ -794,9 +789,8 @@ void cmGlobalGenerator::EnableLanguage( cmSystemTools::SetFatalErrorOccured(); } - for (std::set::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); } } @@ -1021,9 +1015,8 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l, std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar); std::vector extensionList; cmSystemTools::ExpandListArgument(ignoreExts, extensionList); - for (std::vector::iterator i = extensionList.begin(); - i != extensionList.end(); ++i) { - this->IgnoreExtensions[*i] = true; + for (std::string const& i : extensionList) { + this->IgnoreExtensions[i] = true; } } @@ -1035,9 +1028,8 @@ void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l, std::string exts = mf->GetSafeDefinition(extensionsVar); std::vector extensionList; cmSystemTools::ExpandListArgument(exts, extensionList); - for (std::vector::iterator i = extensionList.begin(); - i != extensionList.end(); ++i) { - this->ExtensionToLanguage[*i] = l; + for (std::string const& i : extensionList) { + this->ExtensionToLanguage[i] = l; } } @@ -1075,7 +1067,7 @@ bool cmGlobalGenerator::GetLanguageEnabled(const std::string& l) const void cmGlobalGenerator::ClearEnabledLanguages() { - return this->CMakeInstance->GetState()->ClearEnabledLanguages(); + this->CMakeInstance->GetState()->ClearEnabledLanguages(); } void cmGlobalGenerator::CreateLocalGenerators() @@ -1083,9 +1075,8 @@ void cmGlobalGenerator::CreateLocalGenerators() cmDeleteAll(this->LocalGenerators); this->LocalGenerators.clear(); this->LocalGenerators.reserve(this->Makefiles.size()); - for (std::vector::const_iterator it = this->Makefiles.begin(); - it != this->Makefiles.end(); ++it) { - this->LocalGenerators.push_back(this->CreateLocalGenerator(*it)); + for (cmMakefile* m : this->Makefiles) { + this->LocalGenerators.push_back(this->CreateLocalGenerator(m)); } } @@ -1119,13 +1110,11 @@ void cmGlobalGenerator::Configure() std::vector globalTargets; this->CreateDefaultGlobalTargets(globalTargets); - for (unsigned int i = 0; i < this->Makefiles.size(); ++i) { - cmMakefile* mf = this->Makefiles[i]; + for (cmMakefile* mf : this->Makefiles) { cmTargets* targets = &(mf->GetTargets()); - for (std::vector::iterator gti = globalTargets.begin(); - gti != globalTargets.end(); ++gti) { - targets->insert( - cmTargets::value_type(gti->Name, this->CreateGlobalTarget(*gti, mf))); + for (GlobalTargetInfo const& globalTarget : globalTargets) { + targets->insert(cmTargets::value_type( + globalTarget.Name, this->CreateGlobalTarget(globalTarget, mf))); } } @@ -1145,7 +1134,7 @@ 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(); @@ -1178,9 +1167,8 @@ void cmGlobalGenerator::CreateImportedGenerationObjects( std::find(this->Makefiles.begin(), this->Makefiles.end(), mf); cmLocalGenerator* lg = this->LocalGenerators[std::distance(this->Makefiles.begin(), mfit)]; - for (std::vector::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); } @@ -1192,7 +1180,7 @@ cmExportBuildFileGenerator* cmGlobalGenerator::GetExportedTargetsFile( { std::map::const_iterator it = this->BuildExportSets.find(filename); - return it == this->BuildExportSets.end() ? CM_NULLPTR : it->second; + return it == this->BuildExportSets.end() ? nullptr : it->second; } void cmGlobalGenerator::AddCMP0042WarnTarget(const std::string& target) @@ -1230,10 +1218,8 @@ void cmGlobalGenerator::ComputeBuildFileGenerators() for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { std::vector gens = this->Makefiles[i]->GetExportBuildFileGenerators(); - for (std::vector::const_iterator it = - gens.begin(); - it != gens.end(); ++it) { - (*it)->Compute(this->LocalGenerators[i]); + for (cmExportBuildFileGenerator* g : gens) { + g->Compute(this->LocalGenerators[i]); } } } @@ -1264,15 +1250,12 @@ bool cmGlobalGenerator::Compute() #ifdef CMAKE_BUILD_WITH_CMAKE // Iterate through all targets and set up automoc for those which have // the AUTOMOC, AUTOUIC or AUTORCC property set - std::vector autogenTargets = - this->CreateQtAutoGeneratorsTargets(); + cmQtAutoGenDigestUPV autogenDigests = this->CreateQtAutoGeneratorsTargets(); #endif - unsigned int i; - // 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 +1264,23 @@ 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::iterator it = - autogenTargets.begin(); - it != autogenTargets.end(); ++it) { - cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(*it); + for (cmQtAutoGenDigestUP const& digest : autogenDigests) { + cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(*digest); } + autogenDigests.clear(); #endif - for (i = 0; i < this->LocalGenerators.size(); ++i) { - cmMakefile* mf = this->LocalGenerators[i]->GetMakefile(); - std::vector& gens = mf->GetInstallGenerators(); - for (std::vector::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()) { + g->Compute(localGen); } } @@ -1308,15 +1288,15 @@ 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(); } 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 +1304,8 @@ bool cmGlobalGenerator::Compute() return false; } - for (i = 0; i < this->LocalGenerators.size(); ++i) { - this->LocalGenerators[i]->ComputeHomeRelativeOutputPath(); + for (cmLocalGenerator* localGen : this->LocalGenerators) { + localGen->ComputeHomeRelativeOutputPath(); } return true; @@ -1352,17 +1332,15 @@ void cmGlobalGenerator::Generate() "Generating", (static_cast(i) + 1.0f) / static_cast(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."); } - for (std::map::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, "Could not write export file."); @@ -1375,7 +1353,7 @@ void cmGlobalGenerator::Generate() this->WriteSummary(); - if (this->ExtraGenerator != CM_NULLPTR) { + if (this->ExtraGenerator != nullptr) { this->ExtraGenerator->Generate(); } @@ -1384,10 +1362,8 @@ void cmGlobalGenerator::Generate() w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0042) << "\n"; w << "MACOSX_RPATH is not specified for" " the following targets:\n"; - for (std::set::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()); } @@ -1402,10 +1378,8 @@ void cmGlobalGenerator::Generate() "settings:\n" ; /* clang-format on */ - for (std::set::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()); } @@ -1420,68 +1394,69 @@ bool cmGlobalGenerator::ComputeTargetDepends() return false; } std::vector const& targets = ctd.GetTargets(); - for (std::vector::const_iterator ti = - targets.begin(); - ti != targets.end(); ++ti) { - ctd.GetTargetDirectDepends(*ti, this->TargetDependencies[*ti]); + for (cmGeneratorTarget const* target : targets) { + ctd.GetTargetDirectDepends(target, this->TargetDependencies[target]); } return true; } -std::vector -cmGlobalGenerator::CreateQtAutoGeneratorsTargets() +cmQtAutoGenDigestUPV cmGlobalGenerator::CreateQtAutoGeneratorsTargets() { - std::vector autogenTargets; + cmQtAutoGenDigestUPV autogenDigests; #ifdef CMAKE_BUILD_WITH_CMAKE - for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - std::vector targets = - this->LocalGenerators[i]->GetGeneratorTargets(); - std::vector filteredTargets; - filteredTargets.reserve(targets.size()); - for (std::vector::iterator ti = targets.begin(); - ti != targets.end(); ++ti) { - if ((*ti)->GetType() == cmStateEnums::GLOBAL_TARGET) { + for (cmLocalGenerator* localGen : this->LocalGenerators) { + const std::vector& targets = + localGen->GetGeneratorTargets(); + // Find targets that require AUTOGEN processing + for (cmGeneratorTarget* target : targets) { + if (target->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) { + 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) { continue; } - if ((!(*ti)->GetPropertyAsBool("AUTOMOC") && - !(*ti)->GetPropertyAsBool("AUTOUIC") && - !(*ti)->GetPropertyAsBool("AUTORCC")) || - (*ti)->IsImported()) { + if (target->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") { + + const bool mocEnabled = target->GetPropertyAsBool("AUTOMOC"); + const bool uicEnabled = target->GetPropertyAsBool("AUTOUIC"); + const bool rccEnabled = target->GetPropertyAsBool("AUTORCC"); + if (!mocEnabled && !uicEnabled && !rccEnabled) { continue; } - cmGeneratorTarget* gt = *ti; + std::string qtVersionMajor = + cmQtAutoGeneratorInitializer::GetQtMajorVersion(target); + // don't do anything if there is no Qt4 or Qt5Core (which contains moc) + if (qtVersionMajor != "4" && qtVersionMajor != "5") { + continue; + } - cmQtAutoGeneratorInitializer::InitializeAutogenSources(gt); - filteredTargets.push_back(gt); - } - for (std::vector::iterator ti = - filteredTargets.begin(); - ti != filteredTargets.end(); ++ti) { - cmQtAutoGeneratorInitializer::InitializeAutogenTarget( - this->LocalGenerators[i], *ti); - autogenTargets.push_back(*ti); + { + cmQtAutoGenDigestUP digest(new cmQtAutoGenDigest(target)); + digest->QtVersionMajor = std::move(qtVersionMajor); + digest->QtVersionMinor = + cmQtAutoGeneratorInitializer::GetQtMinorVersion( + target, digest->QtVersionMajor); + digest->MocEnabled = mocEnabled; + digest->UicEnabled = uicEnabled; + digest->RccEnabled = rccEnabled; + autogenDigests.emplace_back(std::move(digest)); + } } } + // Initialize autogen targets + for (const cmQtAutoGenDigestUP& digest : autogenDigests) { + cmQtAutoGeneratorInitializer::InitializeAutogenTarget(*digest); + } #endif - return autogenTargets; + return autogenDigests; } cmLinkLineComputer* cmGlobalGenerator::CreateLinkLineComputer( @@ -1502,17 +1477,15 @@ 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 : targets) { + cmTarget* t = &target.second; if (t->GetType() == cmStateEnums::GLOBAL_TARGET) { continue; } @@ -1537,10 +1510,9 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() std::vector configs; mf->GetConfigurations(configs); - for (std::vector::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,10 +1521,9 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() // The standard include directories for each language // should be treated as system include directories. std::set standardIncludesSet; - for (std::vector::const_iterator li = langs.begin(); - li != langs.end(); ++li) { + for (std::string const& li : langs) { std::string const standardIncludesVar = - "CMAKE_" + *li + "_STANDARD_INCLUDE_DIRECTORIES"; + "CMAKE_" + li + "_STANDARD_INCLUDE_DIRECTORIES"; std::string const standardIncludesStr = mf->GetSafeDefinition(standardIncludesVar); std::vector standardIncludesVec; @@ -1571,8 +1542,8 @@ void cmGlobalGenerator::CreateGeneratorTargets( { if (targetTypes == AllTargets) { cmTargets& targets = mf->GetTargets(); - for (cmTargets::iterator ti = targets.begin(); ti != targets.end(); ++ti) { - cmTarget* t = &ti->second; + for (auto& target : targets) { + cmTarget* t = &target.second; cmGeneratorTarget* gt = new cmGeneratorTarget(t, lg); lg->AddGeneratorTarget(gt); } @@ -1580,9 +1551,8 @@ void cmGlobalGenerator::CreateGeneratorTargets( std::vector itgts = mf->GetImportedTargets(); - for (std::vector::const_iterator j = itgts.begin(); - j != itgts.end(); ++j) { - lg->AddImportedGeneratorTarget(importedMap.find(*j)->second); + for (cmTarget* t : itgts) { + lg->AddImportedGeneratorTarget(importedMap.find(t)->second); } } @@ -1591,13 +1561,11 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes) std::map importedMap; for (unsigned int i = 0; i < this->Makefiles.size(); ++i) { cmMakefile* mf = this->Makefiles[i]; - for (std::vector::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; } } @@ -1644,30 +1612,30 @@ void cmGlobalGenerator::CheckTargetProperties() 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 : targets) { + 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); + target.second.GetOriginalLinkLibraries(); + for (auto const& lib : libs) { + 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 incs; - const char* incDirProp = l->second.GetProperty("INCLUDE_DIRECTORIES"); + const char* incDirProp = + target.second.GetProperty("INCLUDE_DIRECTORIES"); if (!incDirProp) { continue; } @@ -1677,10 +1645,9 @@ void cmGlobalGenerator::CheckTargetProperties() cmSystemTools::ExpandListArgument(incDirs, incs); - for (std::vector::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)"; } @@ -1699,11 +1666,9 @@ void cmGlobalGenerator::CheckTargetProperties() if (!notFoundMap.empty()) { std::string notFoundVars; - for (std::map::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, " @@ -1815,7 +1780,7 @@ int cmGlobalGenerator::Build(const std::string& /*unused*/, output += "\n"; if (!cmSystemTools::RunSingleCommand(cleanCommand, outputPtr, outputPtr, - &retVal, CM_NULLPTR, outputflag, + &retVal, nullptr, outputflag, timeout)) { cmSystemTools::SetRunCommandHideConsole(hideconsole); cmSystemTools::Error("Generator: execution of make clean failed."); @@ -1834,7 +1799,7 @@ int cmGlobalGenerator::Build(const std::string& /*unused*/, output += "\n"; if (!cmSystemTools::RunSingleCommand(makeCommand, outputPtr, outputPtr, - &retVal, CM_NULLPTR, outputflag, + &retVal, nullptr, outputflag, timeout)) { cmSystemTools::SetRunCommandHideConsole(hideconsole); cmSystemTools::Error( @@ -2035,16 +2000,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()); @@ -2057,22 +2021,20 @@ cmMakefile* cmGlobalGenerator::FindMakefile(const std::string& start_dir) const if (i != this->MakefileSearchIndex.end()) { return i->second; } - return CM_NULLPTR; + return nullptr; } ///! Find a local generator by its startdirectory cmLocalGenerator* cmGlobalGenerator::FindLocalGenerator( const std::string& start_dir) const { - for (std::vector::const_iterator it = - this->LocalGenerators.begin(); - it != this->LocalGenerators.end(); ++it) { - std::string sd = (*it)->GetCurrentSourceDirectory(); + for (cmLocalGenerator* lg : this->LocalGenerators) { + std::string sd = lg->GetCurrentSourceDirectory(); if (sd == start_dir) { - return *it; + return lg; } } - return CM_NULLPTR; + return nullptr; } void cmGlobalGenerator::AddAlias(const std::string& name, @@ -2117,7 +2079,7 @@ cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const if (i != this->TargetSearchIndex.end()) { return i->second; } - return CM_NULLPTR; + return nullptr; } cmGeneratorTarget* cmGlobalGenerator::FindGeneratorTargetImpl( @@ -2128,7 +2090,7 @@ cmGeneratorTarget* cmGlobalGenerator::FindGeneratorTargetImpl( if (i != this->GeneratorTargetSearchIndex.end()) { return i->second; } - return CM_NULLPTR; + return nullptr; } cmTarget* cmGlobalGenerator::FindTarget(const std::string& name, @@ -2413,7 +2375,7 @@ void cmGlobalGenerator::AddGlobalTarget_Install( // 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; @@ -2470,16 +2432,15 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti, std::vector no_byproducts; std::vector 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::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: @@ -2556,7 +2517,7 @@ void cmGlobalGenerator::SetExternalMakefileProjectGenerator( cmExternalMakefileProjectGenerator* extraGenerator) { this->ExtraGenerator = extraGenerator; - if (this->ExtraGenerator != CM_NULLPTR) { + if (this->ExtraGenerator != nullptr) { this->ExtraGenerator->SetGlobalGenerator(this); } } @@ -2587,18 +2548,16 @@ void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets, GeneratorVector const& generators) { // loop over all local generators - for (std::vector::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 tgts = (*i)->GetGeneratorTargets(); + const std::vector& tgts = + generator->GetGeneratorTargets(); // loop over all the targets - for (std::vector::iterator l = tgts.begin(); - l != tgts.end(); ++l) { - cmGeneratorTarget* target = *l; + for (cmGeneratorTarget* target : tgts) { if (this->IsRootOnlyTarget(target) && target->GetLocalGenerator() != root) { continue; @@ -2625,8 +2584,8 @@ void cmGlobalGenerator::AddTargetDepends(cmGeneratorTarget const* target, // 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 : ts) { + this->AddTargetDepends(t, projectTargets); } } } @@ -2771,11 +2730,9 @@ void cmGlobalGenerator::WriteRuleHashes(std::string const& pfile) } else { cmGeneratedFileStream fout(pfile.c_str()); fout << "# Hashes of file build rules.\n"; - for (std::map::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"; } } } @@ -2788,16 +2745,14 @@ void cmGlobalGenerator::WriteSummary() fname += "/TargetDirectories.txt"; cmGeneratedFileStream fout(fname.c_str()); - for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - std::vector tgts = - this->LocalGenerators[i]->GetGeneratorTargets(); - for (std::vector::iterator it = tgts.begin(); - it != tgts.end(); ++it) { - if ((*it)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + for (cmLocalGenerator* lg : this->LocalGenerators) { + const std::vector& tgts = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* tgt : tgts) { + if (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } - this->WriteSummary(*it); - fout << (*it)->GetSupportDirectory() << "\n"; + this->WriteSummary(tgt); + fout << tgt->GetSupportDirectory() << "\n"; } } } @@ -2812,7 +2767,12 @@ 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(); @@ -2822,19 +2782,48 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target) cmSystemTools::MakeDirectory(dir.c_str()); cmGeneratedFileStream fout(file.c_str()); + std::vector labels; + // List the target-wide labels. All sources in the target get // these labels. - std::vector labels; - cmSystemTools::ExpandListArgument(value, labels); - if (!labels.empty()) { - fout << "# Target labels\n"; - for (std::vector::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 directoryLabelsList; + std::vector 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 sources; @@ -2843,9 +2832,8 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target) if (configs.empty()) { configs.push_back(""); } - for (std::vector::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::const_iterator sourcesEnd = cmRemoveDuplicates(sources); @@ -2860,10 +2848,9 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target) labels.clear(); Json::Value& lj_source_labels = lj_source["labels"] = Json::arrayValue; cmSystemTools::ExpandListArgument(svalue, labels); - for (std::vector::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); } } } @@ -2881,11 +2868,11 @@ 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] == '\\') { + for (char i : s) { + if (i == '"' || i == '\\') { result += '\\'; } - result += s[i]; + result += i; } return result; } @@ -2905,18 +2892,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 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); } } @@ -2947,9 +2932,8 @@ bool cmGlobalGenerator::GenerateCPackPropertiesFile() cmGeneratedFileStream file(path.c_str()); file << "# CPack properties\n"; - for (cmake::InstalledFilesMap::const_iterator i = installedFiles.begin(); - i != installedFiles.end(); ++i) { - cmInstalledFile const& installedFile = i->second; + 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..18ca682c7 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -3,23 +3,24 @@ #ifndef cmGlobalGenerator_h #define cmGlobalGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include #include #include +#include #include #include #include "cmCustomCommandLines.h" #include "cmExportSetMap.h" +#include "cmQtAutoGenDigest.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" @@ -187,9 +188,15 @@ 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); @@ -289,15 +296,15 @@ public: 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 +317,7 @@ public: TargetDependSet const& GetTargetDirectDepends( const cmGeneratorTarget* target); - const std::map >& GetProjectMap() + const std::map>& GetProjectMap() const { return this->ProjectMap; @@ -416,7 +423,8 @@ protected: virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const; - std::vector CreateQtAutoGeneratorsTargets(); + // Qt auto generators + cmQtAutoGenDigestUPV CreateQtAutoGeneratorsTargets(); std::string SelectMakeProgram(const std::string& makeProgram, const std::string& makeDefault = "") const; @@ -460,9 +468,9 @@ protected: cmake* CMakeInstance; std::vector Makefiles; std::vector LocalGenerators; - cmMakefile* CurrentMakefile; + cmMakefile* CurrentConfigureMakefile; // map from project name to vector of local generators in that project - std::map > ProjectMap; + std::map> ProjectMap; // Set of named installation components requested by the project. std::set InstallComponents; @@ -482,9 +490,10 @@ protected: const char* GetPredefinedTargetsFolder(); private: - typedef CM_UNORDERED_MAP TargetMap; - typedef CM_UNORDERED_MAP GeneratorTargetMap; - typedef CM_UNORDERED_MAP MakefileMap; + typedef std::unordered_map TargetMap; + typedef std::unordered_map + GeneratorTargetMap; + typedef std::unordered_map MakefileMap; // 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. @@ -550,7 +559,7 @@ private: void IndexMakefile(cmMakefile* mf); - 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 @@ -573,7 +582,7 @@ private: // track targets to issue CMP0068 warning for. std::set CMP0068WarnTargets; - mutable std::map > + mutable std::map> FilenameTargetDepends; #if defined(CMAKE_BUILD_WITH_CMAKE) diff --git a/Source/cmGlobalGeneratorFactory.h b/Source/cmGlobalGeneratorFactory.h index d5a6db06e..4e3e7705b 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 #include @@ -45,31 +45,31 @@ 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& names) const CM_OVERRIDE + void GetGenerators(std::vector& names) const override { names.push_back(T::GetActualName()); } /** 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(); } }; #endif diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 42ab4d98a..788a1798a 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -260,7 +260,7 @@ void cmGlobalGhsMultiGenerator::Generate() for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { cmLocalGhsMultiGenerator* lg = static_cast(this->LocalGenerators[i]); - std::vector tgts = lg->GetGeneratorTargets(); + const std::vector& tgts = lg->GetGeneratorTargets(); this->UpdateBuildFiles(tgts); } } @@ -436,9 +436,9 @@ std::string cmGlobalGhsMultiGenerator::GetFileNameFromPath( } void cmGlobalGhsMultiGenerator::UpdateBuildFiles( - std::vector tgts) + const std::vector& tgts) { - for (std::vector::iterator tgtsI = tgts.begin(); + for (std::vector::const_iterator tgtsI = tgts.begin(); tgtsI != tgts.end(); ++tgtsI) { const cmGeneratorTarget* tgt = *tgtsI; if (IsTgtForBuild(tgt)) { diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h index 7b3eebbdf..7d4b2ba7f 100644 --- a/Source/cmGlobalGhsMultiGenerator.h +++ b/Source/cmGlobalGhsMultiGenerator.h @@ -57,7 +57,7 @@ public: /* * Determine what program to use for building the project. */ - bool FindMakeProgram(cmMakefile* mf) CM_OVERRIDE; + bool FindMakeProgram(cmMakefile* mf) override; cmGeneratedFileStream* GetBuildFileStream() { @@ -116,7 +116,7 @@ private: std::vector::const_iterator end, GhsMultiGpj::Types projType); static std::string GetFileNameFromPath(std::string const& path); - void UpdateBuildFiles(std::vector tgts); + void UpdateBuildFiles(const std::vector& tgts); bool IsTgtForBuild(const cmGeneratorTarget* tgt); std::vector TargetSubProjects; diff --git a/Source/cmGlobalKdevelopGenerator.cxx b/Source/cmGlobalKdevelopGenerator.cxx index e72c6e384..b1e630e29 100644 --- a/Source/cmGlobalKdevelopGenerator.cxx +++ b/Source/cmGlobalKdevelopGenerator.cxx @@ -16,7 +16,6 @@ #include "cmsys/Directory.hxx" #include "cmsys/FStream.hxx" -#include #include #include #include @@ -49,15 +48,13 @@ void cmGlobalKdevelopGenerator::Generate() { // for each sub project in the project create // a kdevelop project - for (std::map >::const_iterator - it = this->GlobalGenerator->GetProjectMap().begin(); - it != this->GlobalGenerator->GetProjectMap().end(); ++it) { - std::string outputDir = it->second[0]->GetCurrentBinaryDirectory(); - std::string projectDir = it->second[0]->GetSourceDirectory(); - std::string projectName = it->second[0]->GetProjectName(); + for (auto const& it : this->GlobalGenerator->GetProjectMap()) { + std::string outputDir = it.second[0]->GetCurrentBinaryDirectory(); + std::string projectDir = it.second[0]->GetSourceDirectory(); + std::string projectName = it.second[0]->GetProjectName(); std::string cmakeFilePattern("CMakeLists.txt;*.cmake;"); std::string fileToOpen; - const std::vector& lgs = it->second; + const std::vector& lgs = it.second; // create the project.kdevelop.filelist file if (!this->CreateFilelistFile(lgs, outputDir, projectDir, projectName, cmakeFilePattern, fileToOpen)) { @@ -67,15 +64,12 @@ void cmGlobalKdevelopGenerator::Generate() // try to find the name of an executable so we have something to // run from kdevelop for now just pick the first executable found std::string executable; - for (std::vector::const_iterator lg = lgs.begin(); - lg != lgs.end(); lg++) { + for (cmLocalGenerator* lg : lgs) { std::vector const& targets = - (*lg)->GetGeneratorTargets(); - for (std::vector::const_iterator ti = - targets.begin(); - ti != targets.end(); ti++) { - if ((*ti)->GetType() == cmStateEnums::EXECUTABLE) { - executable = (*ti)->GetLocation(""); + lg->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { + if (target->GetType() == cmStateEnums::EXECUTABLE) { + executable = target->GetLocation(""); break; } } @@ -104,40 +98,35 @@ bool cmGlobalKdevelopGenerator::CreateFilelistFile( std::vector const& hdrExts = this->GlobalGenerator->GetCMakeInstance()->GetHeaderExtensions(); - for (std::vector::const_iterator it = lgs.begin(); - it != lgs.end(); it++) { - cmMakefile* makefile = (*it)->GetMakefile(); + for (cmLocalGenerator* lg : lgs) { + cmMakefile* makefile = lg->GetMakefile(); const std::vector& listFiles = makefile->GetListFiles(); - for (std::vector::const_iterator lt = listFiles.begin(); - lt != listFiles.end(); lt++) { - tmp = *lt; + for (std::string const& listFile : listFiles) { + tmp = listFile; cmSystemTools::ReplaceString(tmp, projectDir.c_str(), ""); // make sure the file is part of this source tree if ((tmp[0] != '/') && (strstr(tmp.c_str(), cmake::GetCMakeFilesDirectoryPostSlash()) == - CM_NULLPTR)) { + nullptr)) { files.insert(tmp); tmp = cmSystemTools::GetFilenameName(tmp); // add all files which dont match the default // */CMakeLists.txt;*cmake; to the file pattern if ((tmp != "CMakeLists.txt") && - (strstr(tmp.c_str(), ".cmake") == CM_NULLPTR)) { + (strstr(tmp.c_str(), ".cmake") == nullptr)) { cmakeFilePattern += tmp + ";"; } } } // get all sources - std::vector targets = (*it)->GetGeneratorTargets(); - for (std::vector::iterator ti = targets.begin(); - ti != targets.end(); ti++) { + const std::vector& targets = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* gt : targets) { std::vector sources; - cmGeneratorTarget* gt = *ti; gt->GetSourceFiles(sources, gt->Target->GetMakefile()->GetSafeDefinition( "CMAKE_BUILD_TYPE")); - for (std::vector::const_iterator si = sources.begin(); - si != sources.end(); si++) { - tmp = (*si)->GetFullPath(); + for (cmSourceFile* sf : sources) { + tmp = sf->GetFullPath(); std::string headerBasename = cmSystemTools::GetFilenamePath(tmp); headerBasename += "/"; headerBasename += cmSystemTools::GetFilenameWithoutExtension(tmp); @@ -146,16 +135,15 @@ bool cmGlobalKdevelopGenerator::CreateFilelistFile( if ((tmp[0] != '/') && (strstr(tmp.c_str(), cmake::GetCMakeFilesDirectoryPostSlash()) == - CM_NULLPTR) && + nullptr) && (cmSystemTools::GetFilenameExtension(tmp) != ".moc")) { files.insert(tmp); // check if there's a matching header around - for (std::vector::const_iterator ext = hdrExts.begin(); - ext != hdrExts.end(); ++ext) { + for (std::string const& hdrExt : hdrExts) { std::string hname = headerBasename; hname += "."; - hname += *ext; + hname += hdrExt; if (cmSystemTools::FileExists(hname.c_str())) { cmSystemTools::ReplaceString(hname, projectDir.c_str(), ""); files.insert(hname); @@ -164,13 +152,12 @@ bool cmGlobalKdevelopGenerator::CreateFilelistFile( } } } - for (std::vector::const_iterator lt = listFiles.begin(); - lt != listFiles.end(); lt++) { - tmp = *lt; + for (std::string const& listFile : listFiles) { + tmp = listFile; cmSystemTools::ReplaceString(tmp, projectDir.c_str(), ""); if ((tmp[0] != '/') && (strstr(tmp.c_str(), cmake::GetCMakeFilesDirectoryPostSlash()) == - CM_NULLPTR)) { + nullptr)) { files.insert(tmp); } } @@ -200,10 +187,9 @@ bool cmGlobalKdevelopGenerator::CreateFilelistFile( } fileToOpen = ""; - for (std::set::const_iterator it = files.begin(); - it != files.end(); it++) { + for (std::string const& file : files) { // get the full path to the file - tmp = cmSystemTools::CollapseFullPath(*it, projectDir.c_str()); + tmp = cmSystemTools::CollapseFullPath(file, projectDir.c_str()); // just select the first source file if (fileToOpen.empty()) { std::string ext = cmSystemTools::GetFilenameExtension(tmp); @@ -296,21 +282,20 @@ void cmGlobalKdevelopGenerator::MergeProjectFiles( return; } - for (std::vector::const_iterator it = lines.begin(); - it != lines.end(); it++) { - const char* line = (*it).c_str(); + for (std::string const& l : lines) { + const char* line = l.c_str(); // skip these tags as they are always replaced - if ((strstr(line, "") != CM_NULLPTR) || - (strstr(line, "") != CM_NULLPTR) || - (strstr(line, "") != CM_NULLPTR) || - (strstr(line, "") != CM_NULLPTR) || - (strstr(line, "") != CM_NULLPTR) || - (strstr(line, "") != CM_NULLPTR)) { + if ((strstr(line, "") != nullptr) || + (strstr(line, "") != nullptr) || + (strstr(line, "") != nullptr) || + (strstr(line, "") != nullptr) || + (strstr(line, "") != nullptr) || + (strstr(line, "") != nullptr)) { continue; } // output the line from the file if it is not one of the above tags - fout << *it << "\n"; + fout << l << "\n"; // if this is the tag output the stuff that goes in the // general tag if (strstr(line, "")) { @@ -433,10 +418,8 @@ void cmGlobalKdevelopGenerator::CreateNewProjectFile( xml.EndElement(); // make xml.StartElement("blacklist"); - for (std::vector::const_iterator dirIt = - this->Blacklist.begin(); - dirIt != this->Blacklist.end(); ++dirIt) { - xml.Element("path", *dirIt); + for (std::string const& dir : this->Blacklist) { + xml.Element("path", dir); } xml.EndElement(); diff --git a/Source/cmGlobalKdevelopGenerator.h b/Source/cmGlobalKdevelopGenerator.h index bdcf8a190..d6c43f3f9 100644 --- a/Source/cmGlobalKdevelopGenerator.h +++ b/Source/cmGlobalKdevelopGenerator.h @@ -3,7 +3,7 @@ #ifndef cmGlobalKdevelopGenerator_h #define cmGlobalKdevelopGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmExternalMakefileProjectGenerator.h" @@ -30,7 +30,7 @@ public: static cmExternalMakefileProjectGeneratorFactory* GetFactory(); - void Generate() CM_OVERRIDE; + void Generate() override; private: /*** Create the foo.kdevelop.filelist file, return false if it doesn't diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h index 6eb21249d..05ab90435 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.h +++ b/Source/cmGlobalNMakeMakefileGenerator.h @@ -27,7 +27,7 @@ public: 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; } diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 2eef9e492..d5531cbe8 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -10,6 +10,7 @@ #include #include #include +#include // IWYU pragma: keep #include #include @@ -32,7 +33,6 @@ #include "cmTarget.h" #include "cmTargetDepend.h" #include "cmVersion.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" class cmLinkLineComputer; @@ -90,12 +90,12 @@ 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(*i)); + sprintf(buf, ".%02x", static_cast(i)); encoded += buf; } } @@ -177,26 +177,23 @@ void cmGlobalNinjaGenerator::WriteBuild( // 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); + for (std::string const& explicitDep : explicitDeps) { + arguments += " " + EncodeIdent(EncodePath(explicitDep), os); } // Write implicit dependencies. if (!implicitDeps.empty()) { arguments += " |"; - for (cmNinjaDeps::const_iterator i = implicitDeps.begin(); - i != implicitDeps.end(); ++i) { - arguments += " " + EncodeIdent(EncodePath(*i), os); + for (std::string const& implicitDep : implicitDeps) { + arguments += " " + EncodeIdent(EncodePath(implicitDep), os); } } // Write order-only dependencies. if (!orderOnlyDeps.empty()) { arguments += " ||"; - for (cmNinjaDeps::const_iterator i = orderOnlyDeps.begin(); - i != orderOnlyDeps.end(); ++i) { - arguments += " " + EncodeIdent(EncodePath(*i), os); + for (std::string const& orderOnlyDep : orderOnlyDeps) { + arguments += " " + EncodeIdent(EncodePath(orderOnlyDep), os); } } @@ -206,18 +203,16 @@ void cmGlobalNinjaGenerator::WriteBuild( // Write outputs files. build += "build"; - for (cmNinjaDeps::const_iterator i = outputs.begin(); i != outputs.end(); - ++i) { - build += " " + EncodeIdent(EncodePath(*i), os); + for (std::string const& output : outputs) { + build += " " + EncodeIdent(EncodePath(output), os); if (this->ComputingUnknownDependencies) { - this->CombinedBuildOutputs.insert(*i); + this->CombinedBuildOutputs.insert(output); } } if (!implicitOuts.empty()) { build += " |"; - for (cmNinjaDeps::const_iterator i = implicitOuts.begin(); - i != implicitOuts.end(); ++i) { - build += " " + EncodeIdent(EncodePath(*i), os); + for (std::string const& implicitOut : implicitOuts) { + build += " " + EncodeIdent(EncodePath(implicitOut), os); } } build += ":"; @@ -227,20 +222,18 @@ void cmGlobalNinjaGenerator::WriteBuild( // 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); + for (auto const& variable : 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) > + (arguments.size() + buildstr.size() + assignments.size() + 1000) > static_cast(cmdLineLimit))) { variable_assignments.str(std::string()); cmGlobalNinjaGenerator::WriteVariable(variable_assignments, "RSP_FILE", @@ -252,7 +245,7 @@ void cmGlobalNinjaGenerator::WriteBuild( *usedResponseFile = useResponseFile; } - os << buildstr << args << assignments; + os << buildstr << arguments << assignments; } void cmGlobalNinjaGenerator::WritePhonyBuild( @@ -311,8 +304,8 @@ void cmGlobalNinjaGenerator::WriteCustomCommandBuild( 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 : deps) { + this->CombinedCustomCommandExplicitDependencies.insert(dep); } } } @@ -465,18 +458,17 @@ 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) + , BuildFileStream(nullptr) + , RulesFileStream(nullptr) + , CompileCommandsStream(nullptr) , Rules() , AllDependencies() , UsingGCCOnWindows(false) @@ -582,8 +574,8 @@ bool cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf) command.push_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" @@ -670,12 +662,11 @@ void cmGlobalNinjaGenerator::EnableLanguage( std::vector const& langs, cmMakefile* mf, bool optional) { this->cmGlobalGenerator::EnableLanguage(langs, mf, optional); - for (std::vector::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 && @@ -741,7 +732,7 @@ void cmGlobalNinjaGenerator::AddRule( description, comment, depfile, deptype, rspfile, rspcontent, restat, generator); - this->RuleCmdLength[name] = (int)command.size(); + this->RuleCmdLength[name] = static_cast(command.size()); } bool cmGlobalNinjaGenerator::HasRule(const std::string& name) @@ -805,7 +796,7 @@ void cmGlobalNinjaGenerator::CloseBuildFileStream() { if (this->BuildFileStream) { delete this->BuildFileStream; - this->BuildFileStream = CM_NULLPTR; + this->BuildFileStream = nullptr; } else { cmSystemTools::Error("Build file stream was not open."); } @@ -847,7 +838,7 @@ void cmGlobalNinjaGenerator::CloseRulesFileStream() { if (this->RulesFileStream) { delete this->RulesFileStream; - this->RulesFileStream = CM_NULLPTR; + this->RulesFileStream = nullptr; } else { cmSystemTools::Error("Rules file stream was not open."); } @@ -870,18 +861,24 @@ 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(this->LocalGenerators[0]); - std::string convPath = ng->ConvertToRelativePath( - this->LocalGenerators[0]->GetState()->GetBinaryDirectory(), path); + const char* bin_dir = ng->GetState()->GetBinaryDirectory(); + std::string convPath = ng->ConvertToRelativePath(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::AddCXXCompileCommand( @@ -928,7 +925,7 @@ void cmGlobalNinjaGenerator::CloseCompileCommandsStream() if (this->CompileCommandsStream) { *this->CompileCommandsStream << "\n]"; delete this->CompileCommandsStream; - this->CompileCommandsStream = CM_NULLPTR; + this->CompileCommandsStream = nullptr; } } @@ -952,15 +949,13 @@ void cmGlobalNinjaGenerator::AddDependencyToAll(const std::string& input) void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies() { - for (std::map >::iterator i = - this->AssumedSourceDependencies.begin(); - i != this->AssumedSourceDependencies.end(); ++i) { + for (auto const& asd : this->AssumedSourceDependencies) { cmNinjaDeps deps; - std::copy(i->second.begin(), i->second.end(), std::back_inserter(deps)); + std::copy(asd.second.begin(), asd.second.end(), std::back_inserter(deps)); WriteCustomCommandBuild(/*command=*/"", /*description=*/"", "Assume dependencies for generated source file.", /*depfile*/ "", /*uses_terminal*/ false, - /*restat*/ true, cmNinjaDeps(1, i->first), deps); + /*restat*/ true, cmNinjaDeps(1, asd.first), deps); } } @@ -1025,22 +1020,20 @@ void cmGlobalNinjaGenerator::AppendTargetDepends( if (target->GetType() == cmStateEnums::GLOBAL_TARGET) { // These depend only on other CMake-provided targets, e.g. "all". std::set const& utils = target->GetUtilities(); - for (std::set::const_iterator i = utils.begin(); - i != utils.end(); ++i) { + for (std::string const& util : utils) { std::string d = target->GetLocalGenerator()->GetCurrentBinaryDirectory() + - std::string("/") + *i; + std::string("/") + util; 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 : targetDeps) { + 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()); @@ -1050,37 +1043,51 @@ void cmGlobalNinjaGenerator::AppendTargetDepends( 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()); - i = this->TargetDependsClosures.insert(e).first; - this->ComputeTargetDependsClosure(target, i->second); - } - std::set const& targets = i->second; - cmNinjaDeps outs; - for (std::set::const_iterator ti = targets.begin(); - ti != targets.end(); ++ti) { - this->AppendTargetOutputs(*ti, outs); - } - std::sort(outs.begin(), outs.end()); + cmNinjaOuts outs; + this->AppendTargetDependsClosure(target, outs, true); + outputs.insert(outputs.end(), outs.begin(), outs.end()); } -void cmGlobalNinjaGenerator::ComputeTargetDependsClosure( - cmGeneratorTarget const* target, std::set& 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. + auto const& targetDeps = this->GetTargetDirectDepends(target); + cmNinjaOuts this_outs; // this will be the new cache entry + + for (auto const& dep_target : targetDeps) { + 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 +1098,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 +1107,7 @@ void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias, std::pair 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 +1116,16 @@ 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) { + for (auto const& ta : TargetAliases) { // Don't write ambiguous aliases. - if (!i->second) { + if (!ta.second) { continue; } cmNinjaDeps deps; - this->AppendTargetOutputs(i->second, deps); + this->AppendTargetOutputs(ta.second, deps); - this->WritePhonyBuild(os, "", cmNinjaDeps(1, i->first), deps); + this->WritePhonyBuild(os, "", cmNinjaDeps(1, ta.first), deps); } } @@ -1129,19 +1135,13 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) os << "# Folder targets.\n\n"; std::map targetsPerFolder; - for (std::vector::const_iterator lgi = - this->LocalGenerators.begin(); - lgi != this->LocalGenerators.end(); ++lgi) { - cmLocalGenerator const* lg = *lgi; + for (cmLocalGenerator const* lg : this->LocalGenerators) { const std::string currentBinaryFolder( lg->GetStateSnapshot().GetDirectory().GetCurrentBinary()); // The directory-level rule should depend on the target-level rules // for all targets in the directory. targetsPerFolder[currentBinaryFolder] = cmNinjaDeps(); - for (std::vector::const_iterator ti = - lg->GetGeneratorTargets().begin(); - ti != lg->GetGeneratorTargets().end(); ++ti) { - cmGeneratorTarget const* gt = *ti; + for (auto gt : lg->GetGeneratorTargets()) { cmStateEnums::TargetType const type = gt->GetType(); if ((type == cmStateEnums::EXECUTABLE || type == cmStateEnums::STATIC_LIBRARY || @@ -1158,11 +1158,9 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) // rules of the subdirectories. std::vector const& children = lg->GetStateSnapshot().GetChildren(); - for (std::vector::const_iterator stateIt = - children.begin(); - stateIt != children.end(); ++stateIt) { + for (cmStateSnapshot const& state : children) { std::string const currentBinaryDir = - stateIt->GetDirectory().GetCurrentBinary(); + state.GetDirectory().GetCurrentBinary(); targetsPerFolder[currentBinaryFolder].push_back( this->ConvertToNinjaPath(currentBinaryDir + "/all")); @@ -1171,11 +1169,9 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) std::string const rootBinaryDir = this->LocalGenerators[0]->GetBinaryDirectory(); - for (std::map::const_iterator it = - targetsPerFolder.begin(); - it != targetsPerFolder.end(); ++it) { + for (auto const& it : targetsPerFolder) { cmGlobalNinjaGenerator::WriteDivider(os); - std::string const& currentBinaryDir = it->first; + std::string const& currentBinaryDir = it.first; // Do not generate a rule for the root binary dir. if (rootBinaryDir.length() >= currentBinaryDir.length()) { @@ -1186,7 +1182,7 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os) cmNinjaDeps output(1); output.push_back(this->ConvertToNinjaPath(currentBinaryDir + "/all")); - this->WritePhonyBuild(os, comment, output, it->second); + this->WritePhonyBuild(os, comment, output, it.second); } } @@ -1220,50 +1216,40 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) // get the list of files that cmake itself has generated as a // product of configuration. - for (std::vector::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& files = - (*i)->GetMakefile()->GetOutputFiles(); - typedef std::vector::const_iterator vect_it; - for (vect_it j = files.begin(); j != files.end(); ++j) { - knownDependencies.insert(this->ConvertToNinjaPath(*j)); + lg->GetMakefile()->GetOutputFiles(); + for (std::string const& file : files) { + knownDependencies.insert(this->ConvertToNinjaPath(file)); } // get list files which are implicit dependencies as well and will be phony // for rebuild manifest - std::vector const& lf = (*i)->GetMakefile()->GetListFiles(); - typedef std::vector::const_iterator vect_it; - for (vect_it j = lf.begin(); j != lf.end(); ++j) { - knownDependencies.insert(this->ConvertToNinjaPath(*j)); + std::vector const& lf = lg->GetMakefile()->GetListFiles(); + for (std::string const& j : lf) { + knownDependencies.insert(this->ConvertToNinjaPath(j)); } std::vector const& ef = - (*i)->GetMakefile()->GetEvaluationFiles(); - for (std::vector::const_iterator li = - ef.begin(); - li != ef.end(); ++li) { + lg->GetMakefile()->GetEvaluationFiles(); + for (cmGeneratorExpressionEvaluationFile* li : ef) { // get all the files created by generator expressions and convert them // to ninja paths - std::vector evaluationFiles = (*li)->GetFiles(); - for (vect_it j = evaluationFiles.begin(); j != evaluationFiles.end(); - ++j) { - knownDependencies.insert(this->ConvertToNinjaPath(*j)); + std::vector evaluationFiles = li->GetFiles(); + for (std::string const& evaluationFile : evaluationFiles) { + 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 >::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 @@ -1285,20 +1271,18 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) bool const inSourceBuild = (rootBuildDirectory == this->GetCMakeInstance()->GetHomeDirectory()); std::vector warnExplicitDepends; - for (std::vector::const_iterator i = - unknownExplicitDepends.begin(); - i != unknownExplicitDepends.end(); ++i) { + for (std::string const& i : unknownExplicitDepends) { // verify the file is in the build directory std::string const absDepPath = - cmSystemTools::CollapseFullPath(*i, rootBuildDirectory.c_str()); + cmSystemTools::CollapseFullPath(i, rootBuildDirectory.c_str()); bool const inBuildDir = cmSystemTools::IsSubDirectory(absDepPath, rootBuildDirectory); if (inBuildDir) { - cmNinjaDeps deps(1, *i); + cmNinjaDeps deps(1, i); this->WritePhonyBuild(os, "", deps, cmNinjaDeps()); if (this->PolicyCMP0058 == cmPolicies::WARN && !inSourceBuild && warnExplicitDepends.size() < 10) { - warnExplicitDepends.push_back(*i); + warnExplicitDepends.push_back(i); } } } @@ -1373,13 +1357,11 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os) /*generator=*/true); cmNinjaDeps implicitDeps; - for (std::vector::const_iterator i = - this->LocalGenerators.begin(); - i != this->LocalGenerators.end(); ++i) { - std::vector const& lf = (*i)->GetMakefile()->GetListFiles(); - for (std::vector::const_iterator fi = lf.begin(); - fi != lf.end(); ++fi) { - implicitDeps.push_back(this->ConvertToNinjaPath(*fi)); + for (cmLocalGenerator* localGen : this->LocalGenerators) { + std::vector const& lf = + localGen->GetMakefile()->GetListFiles(); + for (std::string const& fi : lf) { + implicitDeps.push_back(this->ConvertToNinjaPath(fi)); } } implicitDeps.push_back(this->CMakeCacheFile); @@ -1636,9 +1618,8 @@ int cmcmd_cmake_ninja_depends(std::vector::const_iterator argBeg, 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()); + for (auto const& tdi_include_dir : tdi_include_dirs) { + includes.push_back(tdi_include_dir.asString()); } } } @@ -1659,9 +1640,8 @@ int cmcmd_cmake_ninja_depends(std::vector::const_iterator argBeg, { cmGeneratedFileStream depfile(arg_dep.c_str()); depfile << cmSystemTools::ConvertToUnixOutputPath(arg_pp) << ":"; - for (std::set::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,16 +1650,14 @@ int cmcmd_cmake_ninja_depends(std::vector::const_iterator argBeg, ddi["object"] = arg_obj; Json::Value& ddi_provides = ddi["provides"] = Json::arrayValue; - for (std::set::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::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); } } @@ -1714,24 +1692,24 @@ 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 mfd(new cmMakefile(this, snapshot)); - CM_AUTO_PTR lgd(static_cast( - this->CreateLocalGenerator(mfd.get()))); + auto mfd = cm::make_unique(this, snapshot); + std::unique_ptr lgd( + static_cast( + this->CreateLocalGenerator(mfd.get()))); this->Makefiles.push_back(mfd.release()); this->LocalGenerators.push_back(lgd.release()); } std::vector objects; - for (std::vector::const_iterator ddii = arg_ddis.begin(); - ddii != arg_ddis.end(); ++ddii) { + 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(), + arg_ddi.c_str(), reader.getFormattedErrorMessages().c_str()); return false; } @@ -1740,16 +1718,14 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( 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); @@ -1759,16 +1735,14 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( std::map mod_files; // Populate the module map with those provided by linked targets first. - for (std::vector::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 + "/FortranModules.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(), + linked_target_dir.c_str(), reader.getFormattedErrorMessages().c_str()); return false; } @@ -1783,21 +1757,18 @@ 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::iterator oi = objects.begin(); - oi != objects.end(); ++oi) { - for (std::vector::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 (cmFortranObjectInfo const& object : objects) { + for (std::string const& p : object.Provides) { + std::string const mod = module_dir + p + ".mod"; + mod_files[p] = mod; + tm[p] = mod; } } cmGeneratedFileStream ddf(arg_dd.c_str()); ddf << "ninja_dyndep_version = 1.0\n"; - for (std::vector::iterator oi = objects.begin(); - oi != objects.end(); ++oi) { + for (cmFortranObjectInfo const& object : objects) { std::string const ddComment; std::string const ddRule = "dyndep"; cmNinjaDeps ddOutputs; @@ -1807,19 +1778,17 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile( cmNinjaDeps ddOrderOnlyDeps; cmNinjaVars ddVars; - ddOutputs.push_back(oi->Object); - for (std::vector::iterator i = oi->Provides.begin(); - i != oi->Provides.end(); ++i) { - ddImplicitOuts.push_back(this->ConvertToNinjaPath(mod_files[*i])); + ddOutputs.push_back(object.Object); + for (std::string const& p : object.Provides) { + ddImplicitOuts.push_back(this->ConvertToNinjaPath(mod_files[p])); } - for (std::vector::iterator i = oi->Requires.begin(); - i != oi->Requires.end(); ++i) { - std::map::iterator m = mod_files.find(*i); + for (std::string const& r : object.Requires) { + std::map::iterator m = mod_files.find(r); if (m != mod_files.end()) { ddImplicitDeps.push_back(this->ConvertToNinjaPath(m->second)); } } - if (!oi->Provides.empty()) { + if (!object.Provides.empty()) { ddVars["restat"] = "1"; } @@ -1846,9 +1815,7 @@ int cmcmd_cmake_ninja_dyndep(std::vector::const_iterator argBeg, std::string arg_dd; std::string arg_tdi; std::vector arg_ddis; - for (std::vector::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, "--dd=")) { @@ -1895,16 +1862,15 @@ int cmcmd_cmake_ninja_dyndep(std::vector::const_iterator argBeg, std::vector 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); cm.SetHomeDirectory(dir_top_src); cm.SetHomeOutputDirectory(dir_top_bld); - CM_AUTO_PTR ggd( + std::unique_ptr ggd( static_cast(cm.CreateGlobalGenerator("Ninja"))); if (!ggd.get() || !ggd->WriteDyndepFile(dir_top_src, dir_top_bld, dir_cur_src, dir_cur_bld, diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index b0008f74a..7f80d0806 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -3,12 +3,13 @@ #ifndef cmGlobalNinjaGenerator_h #define cmGlobalNinjaGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include #include #include +#include #include #include @@ -78,7 +79,7 @@ public: 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,7 +99,7 @@ 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 @@ -114,7 +115,7 @@ public: const cmNinjaDeps& orderOnlyDeps, const cmNinjaVars& variables, const std::string& rspfile = std::string(), - int cmdLineLimit = 0, bool* usedResponseFile = CM_NULLPTR); + int cmdLineLimit = 0, bool* usedResponseFile = nullptr); /** * Helper to write a build statement with the special 'phony' rule. @@ -183,11 +184,11 @@ public: return new cmGlobalGeneratorSimpleFactory(); } - ~cmGlobalNinjaGenerator() CM_OVERRIDE {} + ~cmGlobalNinjaGenerator() 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,12 +196,12 @@ 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 const& languages, - cmMakefile* mf, bool optional) CM_OVERRIDE; + cmMakefile* mf, bool optional) override; void GenerateBuildCommand(std::vector& makeCommand, const std::string& makeProgram, @@ -209,34 +210,31 @@ public: const std::string& targetName, const std::string& config, bool fast, bool verbose, std::vector const& makeOptions = - std::vector()) CM_OVERRIDE; + std::vector()) 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 { @@ -248,7 +246,7 @@ public: return this->RulesFileStream; } - std::string ConvertToNinjaPath(const std::string& path) const; + std::string const& ConvertToNinjaPath(const std::string& path) const; struct MapToNinjaPathImpl { @@ -323,6 +321,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,7 +340,7 @@ 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"; } @@ -363,16 +363,16 @@ public: std::vector const& linked_target_dirs); 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 const& languages, - cmMakefile* mf) const CM_OVERRIDE; + cmMakefile* mf) const override; bool CheckFortran(cmMakefile* mf) const; void OpenBuildFileStream(); @@ -446,15 +446,15 @@ private: std::set CombinedBuildOutputs; /// The mapping from source file to assumed dependencies. - std::map > AssumedSourceDependencies; + std::map> AssumedSourceDependencies; typedef std::map TargetAliasMap; TargetAliasMap TargetAliases; - typedef std::map > - TargetDependsClosureMap; - TargetDependsClosureMap TargetDependsClosures; + std::map TargetDependsClosures; + + /// the local cache for calls to ConvertToNinjaPath + mutable std::unordered_map ConvertToNinjaPathCache; std::string NinjaCommand; std::string NinjaVersion; diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 23b3718dc..be4012680 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -38,7 +38,7 @@ cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3(cmake* cm) #else this->UseLinkScript = true; #endif - this->CommandDatabase = CM_NULLPTR; + this->CommandDatabase = nullptr; this->IncludeDirective = "include"; this->DefineWindowsNULL = false; @@ -50,12 +50,11 @@ void cmGlobalUnixMakefileGenerator3::EnableLanguage( std::vector const& languages, cmMakefile* mf, bool optional) { this->cmGlobalGenerator::EnableLanguage(languages, mf, optional); - for (std::vector::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); } } @@ -130,9 +129,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,12 +141,10 @@ 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(); @@ -161,10 +157,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,7 +168,7 @@ 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()) + "/compile_commands.json"; @@ -234,7 +230,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); } @@ -250,9 +246,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2() lg->WriteSpecialTargetsTop(makefileStream); // write the target convenience rules - unsigned int i; - for (i = 0; i < this->LocalGenerators.size(); ++i) { - lg = static_cast(this->LocalGenerators[i]); + for (cmLocalGenerator* localGen : this->LocalGenerators) { + lg = static_cast(localGen); this->WriteConvenienceRules2(makefileStream, lg); } @@ -292,8 +287,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile() // for each cmMakefile get its list of dependencies std::vector lfiles; - for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - lg = static_cast(this->LocalGenerators[i]); + for (cmLocalGenerator* localGen : this->LocalGenerators) { + lg = static_cast(localGen); // Get the list of files contributing to this generation step. lfiles.insert(lfiles.end(), lg->GetMakefile()->GetListFiles().begin(), @@ -316,9 +311,8 @@ 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::const_iterator i = lfiles.begin(); - i != lfiles.end(); ++i) { - cmakefileStream << " \"" << lg->ConvertToRelativePath(currentBinDir, *i) + for (std::string const& f : lfiles) { + cmakefileStream << " \"" << lg->ConvertToRelativePath(currentBinDir, f) << "\"\n"; } cmakefileStream << " )\n\n"; @@ -346,17 +340,15 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile() << "set(CMAKE_MAKEFILE_PRODUCTS\n"; const std::vector& outfiles = lg->GetMakefile()->GetOutputFiles(); - for (std::vector::const_iterator k = outfiles.begin(); - k != outfiles.end(); ++k) { - cmakefileStream << " \"" << lg->ConvertToRelativePath(binDir, *k) + for (std::string const& outfile : outfiles) { + cmakefileStream << " \"" << lg->ConvertToRelativePath(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(this->LocalGenerators[i]); + for (cmLocalGenerator* localGen : this->LocalGenerators) { + lg = static_cast(localGen); tmpStr = lg->GetCurrentBinaryDirectory(); tmpStr += cmake::GetCMakeFilesDirectory(); tmpStr += "/CMakeDirectoryInformation.cmake"; @@ -379,19 +371,18 @@ 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(lGenerators[i]); + for (cmLocalGenerator* lGenerator : lGenerators) { + lg = static_cast(lGenerator); // for all of out targets - std::vector tgts = lg->GetGeneratorTargets(); - for (std::vector::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; + const std::vector& tgts = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* tgt : tgts) { + 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); @@ -414,10 +405,8 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( // The directory-level rule should depend on the target-level rules // for all targets in the directory. std::vector depends; - std::vector targets = lg->GetGeneratorTargets(); - for (std::vector::iterator l = targets.begin(); - l != targets.end(); ++l) { - cmGeneratorTarget* gtarget = *l; + const std::vector& targets = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* gtarget : targets) { int type = gtarget->GetType(); if ((type == cmStateEnums::EXECUTABLE) || (type == cmStateEnums::STATIC_LIBRARY) || @@ -440,9 +429,8 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( // The directory-level rule should depend on the directory-level // rules of the subdirectories. std::vector children = lg->GetStateSnapshot().GetChildren(); - for (std::vector::const_iterator ci = children.begin(); - ci != children.end(); ++ci) { - std::string subdir = ci->GetDirectory().GetCurrentBinary(); + for (cmStateSnapshot const& c : children) { + std::string subdir = c.GetDirectory().GetCurrentBinary(); subdir += "/"; subdir += pass; depends.push_back(subdir); @@ -450,7 +438,7 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2( // 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); } @@ -542,15 +530,12 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules( depends.push_back("cmake_check_build_system"); // write the target convenience rules - unsigned int i; - cmLocalUnixMakefileGenerator3* lg; - for (i = 0; i < this->LocalGenerators.size(); ++i) { - lg = static_cast(this->LocalGenerators[i]); + for (cmLocalGenerator* localGen : this->LocalGenerators) { + cmLocalUnixMakefileGenerator3* lg = + static_cast(localGen); // for each target Generate the rule files for each target. - std::vector targets = lg->GetGeneratorTargets(); - for (std::vector::iterator t = targets.begin(); - t != targets.end(); ++t) { - cmGeneratorTarget* gtarget = *t; + const std::vector& targets = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* gtarget : targets) { // Don't emit the same rule twice (e.g. two targets with the same // simple name) int type = gtarget->GetType(); @@ -629,10 +614,8 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( depends.push_back("cmake_check_build_system"); // for each target Generate the rule files for each target. - std::vector targets = lg->GetGeneratorTargets(); - for (std::vector::iterator t = targets.begin(); - t != targets.end(); ++t) { - cmGeneratorTarget* gtarget = *t; + const std::vector& targets = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* gtarget : targets) { int type = gtarget->GetType(); std::string name = gtarget->GetName(); if (!name.empty() && ((type == cmStateEnums::EXECUTABLE) || @@ -680,11 +663,10 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2( { std::ostringstream progressArg; const char* sep = ""; - std::vector& progFiles = + std::vector const& progFiles = this->ProgressMap[gtarget].Marks; - for (std::vector::iterator i = progFiles.begin(); - i != progFiles.end(); ++i) { - progressArg << sep << *i; + for (unsigned long progFile : progFiles) { + progressArg << sep << progFile; sep = ","; } progress.Arg = progressArg.str(); @@ -803,15 +785,9 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks() { this->DirectoryTargetsMap.clear(); // Loop over all targets in all local generators. - for (std::vector::const_iterator lgi = - this->LocalGenerators.begin(); - lgi != this->LocalGenerators.end(); ++lgi) { - cmLocalGenerator* lg = *lgi; - std::vector targets = lg->GetGeneratorTargets(); - for (std::vector::const_iterator t = targets.begin(); - t != targets.end(); ++t) { - cmGeneratorTarget* gt = *t; - + for (cmLocalGenerator* lg : this->LocalGenerators) { + const std::vector& targets = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* gt : targets) { cmLocalGenerator* tlg = gt->GetLocalGenerator(); if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY || @@ -835,9 +811,8 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks() // 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 : tgtdeps) { + targetSet.insert(tgtdep); } } } @@ -851,12 +826,11 @@ size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInTarget( 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 : depends) { + if (depend->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } - count += this->CountProgressMarksInTarget(*di, emitted); + count += this->CountProgressMarksInTarget(depend, emitted); } } return count; @@ -869,9 +843,8 @@ size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInAll( std::set emitted; std::set const& targets = this->DirectoryTargetsMap[lg->GetStateSnapshot()]; - for (std::set::const_iterator t = targets.begin(); - t != targets.end(); ++t) { - count += this->CountProgressMarksInTarget(*t, emitted); + for (cmGeneratorTarget const* target : targets) { + count += this->CountProgressMarksInTarget(target, emitted); } return count; } @@ -910,10 +883,9 @@ void cmGlobalUnixMakefileGenerator3::AppendGlobalTargetDepends( std::vector& 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 : depends_set) { // Create the target-level dependency. - cmGeneratorTarget const* dep = *i; + cmGeneratorTarget const* dep = i; if (dep->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } @@ -943,19 +915,16 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule( std::set emittedTargets; // for each local generator - unsigned int i; - cmLocalUnixMakefileGenerator3* lg2; - for (i = 0; i < this->LocalGenerators.size(); ++i) { - lg2 = - static_cast(this->LocalGenerators[i]); + for (cmLocalGenerator* localGen : this->LocalGenerators) { + cmLocalUnixMakefileGenerator3* lg2 = + static_cast(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 targets = lg2->GetGeneratorTargets(); - for (std::vector::iterator t = targets.begin(); - t != targets.end(); ++t) { - cmGeneratorTarget* target = *t; + const std::vector& targets = + lg2->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { cmStateEnums::TargetType type = target->GetType(); if ((type == cmStateEnums::EXECUTABLE) || (type == cmStateEnums::STATIC_LIBRARY) || @@ -974,11 +943,9 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule( } } } - std::vector const& localHelp = lg->GetLocalHelp(); - for (std::vector::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, @@ -993,10 +960,9 @@ bool cmGlobalUnixMakefileGenerator3::NeedRequiresStep( target->GetLanguages( languages, target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE")); - for (std::set::const_iterator l = languages.begin(); - l != languages.end(); ++l) { + for (std::string const& l : languages) { std::string var = "CMAKE_NEEDS_REQUIRES_STEP_"; - var += *l; + var += l; var += "_FLAG"; if (target->Target->GetMakefile()->GetDefinition(var)) { return true; diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index a656102fb..d601f8845 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 #include @@ -68,7 +68,7 @@ public: } ///! Get the name for the generator. - std::string GetName() const CM_OVERRIDE + 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 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&); @@ -134,7 +134,7 @@ public: const std::string& targetName, const std::string& config, bool fast, bool verbose, std::vector const& makeOptions = - std::vector()) CM_OVERRIDE; + std::vector()) override; /** Record per-target progress information. */ void RecordTargetProgress(cmMakefileTargetGenerator* tg); @@ -149,9 +149,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; @@ -178,37 +178,31 @@ protected: 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 @@ -247,13 +241,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::StrictWeakOrder> DirectoryTargetsMap; - void InitializeProgressMarks() CM_OVERRIDE; + void InitializeProgressMarks() override; }; #endif diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 4fff11a9f..8c9e4616e 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -51,7 +51,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 +73,22 @@ 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& names) const CM_OVERRIDE + void GetGenerators(std::vector& names) const override { names.push_back(vs10generatorName); names.push_back(vs10generatorName + std::string(" IA64")); names.push_back(vs10generatorName + std::string(" Win64")); } - 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; } }; cmGlobalGeneratorFactory* cmGlobalVisualStudio10Generator::NewFactory() @@ -407,14 +407,14 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf) bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset( std::string& toolset) const { - toolset = ""; + toolset.clear(); return false; } bool cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset( std::string& toolset) const { - toolset = ""; + toolset.clear(); return false; } @@ -495,7 +495,7 @@ const char* cmGlobalVisualStudio10Generator::GetPlatformToolset() const { std::string const& toolset = this->GetPlatformToolsetString(); if (toolset.empty()) { - return CM_NULLPTR; + return nullptr; } return toolset.c_str(); } @@ -519,7 +519,7 @@ cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const if (!this->GeneratorToolsetHostArchitecture.empty()) { return this->GeneratorToolsetHostArchitecture.c_str(); } - return CM_NULLPTR; + return nullptr; } const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const @@ -527,7 +527,7 @@ const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const if (!this->GeneratorToolsetCuda.empty()) { return this->GeneratorToolsetCuda.c_str(); } - return CM_NULLPTR; + return nullptr; } std::string const& @@ -695,7 +695,12 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf) xw.Content(this->WindowsTargetPlatformVersion); xw.EndElement(); // WindowsTargetPlatformVersion } - if (this->GetPlatformName() == "ARM") { + if (this->GetPlatformName() == "ARM64") { + xw.StartElement("WindowsSDKDesktopARM64Support"); + xw.Content("true"); + xw.EndElement(); // WindowsSDK64DesktopARMSupport + } + else if (this->GetPlatformName() == "ARM") { xw.StartElement("WindowsSDKDesktopARMSupport"); xw.Content("true"); xw.EndElement(); // WindowsSDKDesktopARMSupport @@ -971,7 +976,7 @@ cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const cmIDEFlagTable const* table = this->ToolsetOptions.GetClFlagTable( this->GetPlatformName(), this->GetPlatformToolsetString()); - return (table != CM_NULLPTR) ? table : this->DefaultClFlagTable; + return (table != nullptr) ? table : this->DefaultClFlagTable; } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable() @@ -980,7 +985,7 @@ cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable() cmIDEFlagTable const* table = this->ToolsetOptions.GetCSharpFlagTable( this->GetPlatformName(), this->GetPlatformToolsetString()); - return (table != CM_NULLPTR) ? table : this->DefaultCSharpFlagTable; + return (table != nullptr) ? table : this->DefaultCSharpFlagTable; } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const @@ -988,7 +993,7 @@ cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const cmIDEFlagTable const* table = this->ToolsetOptions.GetRcFlagTable( this->GetPlatformName(), this->GetPlatformToolsetString()); - return (table != CM_NULLPTR) ? table : this->DefaultRcFlagTable; + return (table != nullptr) ? table : this->DefaultRcFlagTable; } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const @@ -996,7 +1001,7 @@ cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const cmIDEFlagTable const* table = this->ToolsetOptions.GetLibFlagTable( this->GetPlatformName(), this->GetPlatformToolsetString()); - return (table != CM_NULLPTR) ? table : this->DefaultLibFlagTable; + return (table != nullptr) ? table : this->DefaultLibFlagTable; } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const @@ -1004,7 +1009,7 @@ cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const cmIDEFlagTable const* table = this->ToolsetOptions.GetLinkFlagTable( this->GetPlatformName(), this->GetPlatformToolsetString()); - return (table != CM_NULLPTR) ? table : this->DefaultLinkFlagTable; + return (table != nullptr) ? table : this->DefaultLinkFlagTable; } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaFlagTable() const @@ -1023,7 +1028,7 @@ cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const cmIDEFlagTable const* table = this->ToolsetOptions.GetMasmFlagTable( this->GetPlatformName(), this->GetPlatformToolsetString()); - return (table != CM_NULLPTR) ? table : this->DefaultMasmFlagTable; + return (table != nullptr) ? table : this->DefaultMasmFlagTable; } cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 4a5c2454b..5f80c7342 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -98,7 +98,7 @@ public: virtual const char* GetToolsVersion() { return "4.0"; } - bool FindMakeProgram(cmMakefile* mf) CM_OVERRIDE; + bool FindMakeProgram(cmMakefile* mf) override; static std::string GetInstalledNsightTegraVersion(); diff --git a/Source/cmGlobalVisualStudio11Generator.cxx b/Source/cmGlobalVisualStudio11Generator.cxx index d37d4b095..cb3b0477f 100644 --- a/Source/cmGlobalVisualStudio11Generator.cxx +++ b/Source/cmGlobalVisualStudio11Generator.cxx @@ -35,7 +35,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,14 +68,14 @@ 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& names) const CM_OVERRIDE + void GetGenerators(std::vector& names) const override { names.push_back(vs11generatorName); names.push_back(vs11generatorName + std::string(" ARM")); @@ -89,8 +89,8 @@ public: } } - 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; } }; cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory() diff --git a/Source/cmGlobalVisualStudio11Generator.h b/Source/cmGlobalVisualStudio11Generator.h index b4b327d8a..8b75aadbf 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 #include diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx index de62ff0ac..a9c605cad 100644 --- a/Source/cmGlobalVisualStudio12Generator.cxx +++ b/Source/cmGlobalVisualStudio12Generator.cxx @@ -35,7 +35,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 +57,22 @@ 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& names) const CM_OVERRIDE + void GetGenerators(std::vector& names) const override { names.push_back(vs12generatorName); names.push_back(vs12generatorName + std::string(" ARM")); names.push_back(vs12generatorName + std::string(" Win64")); } - 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; } }; cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory() diff --git a/Source/cmGlobalVisualStudio12Generator.h b/Source/cmGlobalVisualStudio12Generator.h index ebc95bb63..5ba21a662 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 #include @@ -32,7 +32,7 @@ public: virtual const char* GetToolsVersion() { return "12.0"; } protected: 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); diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index c8cf02cdd..97d531378 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -35,7 +35,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 +57,22 @@ 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& names) const CM_OVERRIDE + void GetGenerators(std::vector& names) const override { names.push_back(vs14generatorName); names.push_back(vs14generatorName + std::string(" ARM")); names.push_back(vs14generatorName + std::string(" Win64")); } - 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; } }; cmGlobalGeneratorFactory* cmGlobalVisualStudio14Generator::NewFactory() @@ -151,6 +151,13 @@ bool cmGlobalVisualStudio14Generator::SelectWindows10SDK(cmMakefile* mf, mf->IssueMessage(cmake::FATAL_ERROR, e.str()); return false; } + 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().c_str(), -1); + } mf->AddDefinition("CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION", this->WindowsTargetPlatformVersion.c_str()); return true; diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h index 0ce9a5641..425fb227f 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 #include diff --git a/Source/cmGlobalVisualStudio15Generator.cxx b/Source/cmGlobalVisualStudio15Generator.cxx index ce1ba007f..d2bf7cca6 100644 --- a/Source/cmGlobalVisualStudio15Generator.cxx +++ b/Source/cmGlobalVisualStudio15Generator.cxx @@ -69,8 +69,8 @@ public: names.push_back(vs15generatorName + std::string(" Win64")); } - 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; } }; cmGlobalGeneratorFactory* cmGlobalVisualStudio15Generator::NewFactory() diff --git a/Source/cmGlobalVisualStudio15Generator.h b/Source/cmGlobalVisualStudio15Generator.h index 4be88f44f..e93488243 100644 --- a/Source/cmGlobalVisualStudio15Generator.h +++ b/Source/cmGlobalVisualStudio15Generator.h @@ -3,7 +3,7 @@ #ifndef cmGlobalVisualStudio15Generator_h #define cmGlobalVisualStudio15Generator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -28,7 +28,7 @@ public: virtual const char* GetToolsVersion() { return "15.0"; } protected: - bool InitializeWindows(cmMakefile* mf) CM_OVERRIDE; + bool InitializeWindows(cmMakefile* mf) override; virtual bool SelectWindowsStoreToolset(std::string& toolset) const; virtual const char* GetIDEVersion() { return "15.0"; } @@ -44,8 +44,8 @@ protected: // Check for a Win 8 SDK known to the registry or VS installer tool. bool IsWin81SDKInstalled() const; - std::string FindMSBuildCommand() CM_OVERRIDE; - std::string FindDevEnvCommand() CM_OVERRIDE; + std::string FindMSBuildCommand() override; + std::string FindDevEnvCommand() override; private: class Factory; diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index b155f5b55..a14b5f753 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -334,7 +334,7 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile( // output the SLN file void cmGlobalVisualStudio7Generator::OutputSLNFile() { - std::map >::iterator it; + std::map>::iterator it; for (it = this->ProjectMap.begin(); it != this->ProjectMap.end(); ++it) { this->OutputSLNFile(it->second[0], it->second); } @@ -403,7 +403,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( std::string dir = lg->GetCurrentBinaryDirectory(); dir = root->ConvertToRelativePath(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; @@ -418,7 +418,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( std::vector tokens = cmSystemTools::SplitString(targetFolder, '/', false); - std::string cumulativePath = ""; + std::string cumulativePath; for (std::vector::iterator iter = tokens.begin(); iter != tokens.end(); ++iter) { @@ -467,7 +467,7 @@ 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 >::iterator iter = + for (std::map>::iterator iter = VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter) { std::string fullName = iter->first; @@ -487,7 +487,7 @@ void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout) void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout) { - for (std::map >::iterator iter = + for (std::map>::iterator iter = VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter) { std::string key(iter->first); @@ -708,7 +708,7 @@ std::set cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild( const char* propertyValue = target->Target->GetMakefile()->GetDefinition(propertyName); cmGeneratorExpression ge; - CM_AUTO_PTR cge = + std::unique_ptr cge = ge.Parse(propertyValue); if (cmSystemTools::IsOn( cge->Evaluate(target->GetLocalGenerator(), *i))) { diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 32a8d6056..c5aced44f 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -91,7 +91,7 @@ public: const char* GetIntelProjectVersion(); - bool FindMakeProgram(cmMakefile* mf) CM_OVERRIDE; + bool FindMakeProgram(cmMakefile* mf) override; /** Is the Microsoft Assembler enabled? */ bool IsMasmEnabled() const { return this->MasmEnabled; } @@ -156,7 +156,7 @@ protected: virtual void WriteFolders(std::ostream& fout); virtual void WriteFoldersContent(std::ostream& fout); - std::map > VisualStudioFolders; + std::map> VisualStudioFolders; // Set during OutputSLNFile with the name of the current project. // There is one SLN file per project. diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index f06a8a1c6..cc1d1a27b 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -17,7 +17,7 @@ class cmGlobalVisualStudio8Generator::Factory : public cmGlobalGeneratorFactory { public: cmGlobalGenerator* CreateGlobalGenerator(const std::string& name, - cmake* cm) const CM_OVERRIDE + cmake* cm) const override { if (strncmp(name.c_str(), vs8generatorName, sizeof(vs8generatorName) - 1) != 0) { @@ -51,14 +51,14 @@ public: return ret; } - void GetDocumentation(cmDocumentationEntry& entry) const CM_OVERRIDE + void GetDocumentation(cmDocumentationEntry& entry) const 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& names) const CM_OVERRIDE + void GetGenerators(std::vector& names) const override { names.push_back(vs8generatorName); names.push_back(vs8generatorName + std::string(" Win64")); @@ -73,8 +73,8 @@ public: } } - 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; } }; cmGlobalGeneratorFactory* cmGlobalVisualStudio8Generator::NewFactory() @@ -301,7 +301,7 @@ 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 no_byproducts; if (cmSourceFile* file = mf->AddCustomCommandToOutput( stamps, no_byproducts, listFiles, no_main_dependency, commandLines, @@ -320,10 +320,10 @@ void cmGlobalVisualStudio8Generator::AddExtraIDETargets() cmGlobalVisualStudio7Generator::AddExtraIDETargets(); if (this->AddCheckTarget()) { for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - std::vector tgts = + const std::vector& tgts = this->LocalGenerators[i]->GetGeneratorTargets(); // All targets depend on the build-system check target. - for (std::vector::iterator ti = tgts.begin(); + for (std::vector::const_iterator ti = tgts.begin(); ti != tgts.end(); ++ti) { if ((*ti)->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) { (*ti)->Target->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET); diff --git a/Source/cmGlobalVisualStudio9Generator.cxx b/Source/cmGlobalVisualStudio9Generator.cxx index b1634e2ca..0abb3488e 100644 --- a/Source/cmGlobalVisualStudio9Generator.cxx +++ b/Source/cmGlobalVisualStudio9Generator.cxx @@ -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,14 +52,14 @@ 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& names) const CM_OVERRIDE + void GetGenerators(std::vector& names) const override { names.push_back(vs9generatorName); names.push_back(vs9generatorName + std::string(" Win64")); @@ -75,8 +75,8 @@ public: } } - 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; } }; cmGlobalGeneratorFactory* cmGlobalVisualStudio9Generator::NewFactory() diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index bbff48eb6..0651536a9 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -58,7 +58,7 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets() const char* no_working_dir = 0; std::vector no_depends; cmCustomCommandLines no_commands; - std::map >::iterator it; + std::map>::iterator it; for (it = this->ProjectMap.begin(); it != this->ProjectMap.end(); ++it) { std::vector& gen = it->second; // add the ALL_BUILD to the first local generator of each project @@ -82,8 +82,10 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets() // Now make all targets depend on the ALL_BUILD target for (std::vector::iterator i = gen.begin(); i != gen.end(); ++i) { - std::vector targets = (*i)->GetGeneratorTargets(); - for (std::vector::iterator t = targets.begin(); + const std::vector& targets = + (*i)->GetGeneratorTargets(); + for (std::vector::const_iterator t = + targets.begin(); t != targets.end(); ++t) { cmGeneratorTarget* tgt = *t; if (tgt->GetType() == cmStateEnums::GLOBAL_TARGET || @@ -148,7 +150,7 @@ void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros() { std::string dir = this->GetUserMacrosDirectory(); - if (dir != "") { + if (!dir.empty()) { std::string src = cmSystemTools::GetCMakeRoot(); src += "/Templates/" CMAKE_VSMACROS_FILENAME; @@ -188,7 +190,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()) && @@ -293,13 +295,15 @@ bool cmGlobalVisualStudioGenerator::ComputeTargetDepends() if (!this->cmGlobalGenerator::ComputeTargetDepends()) { return false; } - std::map >::iterator it; + std::map>::iterator it; for (it = this->ProjectMap.begin(); it != this->ProjectMap.end(); ++it) { std::vector& gen = it->second; for (std::vector::iterator i = gen.begin(); i != gen.end(); ++i) { - std::vector targets = (*i)->GetGeneratorTargets(); - for (std::vector::iterator ti = targets.begin(); + const std::vector& targets = + (*i)->GetGeneratorTargets(); + for (std::vector::const_iterator ti = + targets.begin(); ti != targets.end(); ++ti) { this->ComputeVSTargetDepends(*ti); } diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index 3c43ccdd2..62bfd3bdb 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 #include @@ -118,7 +118,7 @@ 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; diff --git a/Source/cmGlobalWatcomWMakeGenerator.h b/Source/cmGlobalWatcomWMakeGenerator.h index b2d6d5d71..e8b3a73c9 100644 --- a/Source/cmGlobalWatcomWMakeGenerator.h +++ b/Source/cmGlobalWatcomWMakeGenerator.h @@ -3,7 +3,7 @@ #ifndef cmGlobalWatcomWMakeGenerator_h #define cmGlobalWatcomWMakeGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmGlobalGeneratorFactory.h" #include "cmGlobalUnixMakefileGenerator3.h" @@ -29,7 +29,7 @@ public: return new cmGlobalGeneratorSimpleFactory(); } ///! Get the name for the generator. - std::string GetName() const CM_OVERRIDE + std::string GetName() const override { return cmGlobalWatcomWMakeGenerator::GetActualName(); } @@ -43,10 +43,10 @@ public: * extension, pthreads, byte order etc. */ void EnableLanguage(std::vector 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; } }; #endif diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 903796123..c79ee475c 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -5,10 +5,12 @@ #include "cmsys/RegularExpression.hxx" #include #include +#include // IWYU pragma: keep #include #include #include +#include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" #include "cmCustomCommandGenerator.h" #include "cmDocumentationEntry.h" @@ -29,7 +31,6 @@ #include "cmXCode21Object.h" #include "cmXCodeObject.h" #include "cmXCodeScheme.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" struct cmLinkImplementation; @@ -46,8 +47,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 +61,7 @@ public: } } } - void CharacterDataHandler(const char* data, int length) + void CharacterDataHandler(const char* data, int length) override { this->Data.append(data, length); } @@ -79,7 +83,7 @@ class cmGlobalXCodeGenerator::BuildObjectListOrString public: BuildObjectListOrString(cmGlobalXCodeGenerator* gen, bool buildObjectList) : Generator(gen) - , Group(0) + , Group(nullptr) , Empty(true) { if (buildObjectList) { @@ -107,9 +111,8 @@ public: { if (this->Group) { return this->Group; - } else { - return this->Generator->CreateString(this->String); } + return this->Generator->CreateString(this->String); } }; @@ -117,20 +120,20 @@ 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& names) const CM_OVERRIDE + void GetGenerators(std::vector& names) const override { names.push_back(cmGlobalXCodeGenerator::GetActualName()); } - bool SupportsToolset() const CM_OVERRIDE { return true; } - bool SupportsPlatform() const CM_OVERRIDE { return false; } + bool SupportsToolset() const override { return true; } + bool SupportsPlatform() const override { return false; } }; cmGlobalXCodeGenerator::cmGlobalXCodeGenerator( @@ -140,10 +143,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,16 +163,18 @@ 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) && + if (cmSystemTools::RunSingleCommand("xcode-select --print-path", &out, + nullptr, nullptr, nullptr, + cmSystemTools::OUTPUT_NONE) && (pos = out.find(".app/"), pos != std::string::npos)) { versionFile = out.substr(0, pos + 5) + "Contents/version.plist"; } @@ -193,11 +198,11 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator( if (version_number < 30) { cm->IssueMessage(cmake::FATAL_ERROR, "Xcode " + version_string + " not supported."); - return CM_NULLPTR; + return nullptr; } - CM_AUTO_PTR gg( - new cmGlobalXCodeGenerator(cm, version_string, version_number)); + auto gg = cm::make_unique(cm, version_string, + version_number); return gg.release(); #else std::cerr << "CMake should be built with cmake to use Xcode, " @@ -235,10 +240,9 @@ std::string cmGlobalXCodeGenerator::FindXcodeBuildCommand() makeProgram = "xcodebuild"; } return makeProgram; - } else { - // Use cmakexbuild wrapper to suppress environment dump from output. - return cmSystemTools::GetCMakeCommand() + "xbuild"; } + // Use cmakexbuild wrapper to suppress environment dump from output. + return cmSystemTools::GetCMakeCommand() + "xbuild"; } bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts, @@ -330,7 +334,7 @@ cmLocalGenerator* cmGlobalXCodeGenerator::CreateLocalGenerator(cmMakefile* mf) void cmGlobalXCodeGenerator::AddExtraIDETargets() { - std::map >::iterator it; + std::map>::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) { @@ -347,7 +351,7 @@ void cmGlobalXCodeGenerator::Generate() if (cmSystemTools::GetErrorOccuredFlag()) { return; } - std::map >::iterator it; + std::map>::iterator it; for (it = this->ProjectMap.begin(); it != this->ProjectMap.end(); ++it) { cmLocalGenerator* root = it->second[0]; this->SetGenerationRoot(root); @@ -391,7 +395,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets( cmMakefile* mf = root->GetMakefile(); // Add ALL_BUILD - const char* no_working_directory = 0; + const char* no_working_directory = nullptr; std::vector no_depends; cmTarget* allbuild = mf->AddUtilityCommand("ALL_BUILD", true, no_depends, no_working_directory, @@ -433,18 +437,13 @@ void cmGlobalXCodeGenerator::AddExtraTargets( // now make the allbuild depend on all the non-utility targets // in the project - for (std::vector::iterator i = gens.begin(); - i != gens.end(); ++i) { - cmLocalGenerator* lg = *i; - if (this->IsExcluded(root, *i)) { + for (auto& gen : gens) { + if (this->IsExcluded(root, gen)) { continue; } - std::vector tgts = lg->GetGeneratorTargets(); - for (std::vector::iterator l = tgts.begin(); - l != tgts.end(); l++) { - cmGeneratorTarget* target = *l; - + const std::vector& tgts = gen->GetGeneratorTargets(); + for (auto target : tgts) { if (target->GetType() == cmStateEnums::GLOBAL_TARGET) { continue; } @@ -470,7 +469,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets( cmCustomCommandLines commandLines; commandLines.push_back(makeHelper); std::vector 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); @@ -482,7 +481,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets( } // Refer to the build configuration file for easy editing. - listfile = lg->GetCurrentSourceDirectory(); + listfile = gen->GetCurrentSourceDirectory(); listfile += "/"; listfile += "CMakeLists.txt"; target->AddSource(listfile); @@ -494,9 +493,8 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile( cmLocalGenerator* root, std::vector const& gens) { std::vector lfiles; - for (std::vector::const_iterator gi = gens.begin(); - gi != gens.end(); ++gi) { - std::vector const& lf = (*gi)->GetMakefile()->GetListFiles(); + for (auto gen : gens) { + std::vector const& lf = gen->GetMakefile()->GetListFiles(); lfiles.insert(lfiles.end(), lf.begin(), lf.end()); } @@ -556,8 +554,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 +569,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: // @@ -668,8 +666,10 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( if (const char* cflags = sf->GetProperty("COMPILE_FLAGS")) { cmGeneratorExpression ge; std::string configName = "NO-PER-CONFIG-SUPPORT-IN-XCODE"; - CM_AUTO_PTR compiledExpr = ge.Parse(cflags); - const char* processed = compiledExpr->Evaluate(lg, configName); + std::unique_ptr compiledExpr = + ge.Parse(cflags); + const char* processed = + compiledExpr->Evaluate(lg, configName, false, gtgt); if (compiledExpr->GetHadContextSensitiveCondition()) { std::ostringstream e; /* clang-format off */ @@ -925,18 +925,16 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( cmLocalGenerator* gen, std::vector& targets) { this->SetCurrentLocalGenerator(gen); - std::vector tgts = + const std::vector& tgts = this->CurrentLocalGenerator->GetGeneratorTargets(); typedef std::map cmSortedTargets; cmSortedTargets sortedTargets; - for (std::vector::iterator l = tgts.begin(); - l != tgts.end(); l++) { - sortedTargets[(*l)->GetName()] = *l; + for (auto tgt : tgts) { + sortedTargets[tgt->GetName()] = tgt; } - for (cmSortedTargets::iterator l = sortedTargets.begin(); - l != sortedTargets.end(); l++) { - cmGeneratorTarget* gtgt = l->second; + for (auto& sortedTarget : sortedTargets) { + cmGeneratorTarget* gtgt = sortedTarget.second; std::string targetName = gtgt->GetName(); @@ -1018,7 +1016,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( } std::string const& obj = (*oi)->GetFullPath(); cmXCodeObject* xsf = - this->CreateXCodeSourceFileFromPath(obj, gtgt, "", 0); + this->CreateXCodeSourceFileFromPath(obj, gtgt, "", nullptr); externalObjFiles.push_back(xsf); } } @@ -1028,10 +1026,10 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( bool isBundleTarget = gtgt->GetPropertyAsBool("MACOSX_BUNDLE"); bool isCFBundleTarget = gtgt->IsCFBundleOnApple(); - cmXCodeObject* buildFiles = 0; + cmXCodeObject* buildFiles = nullptr; // create source build phase - cmXCodeObject* sourceBuildPhase = 0; + cmXCodeObject* sourceBuildPhase = nullptr; if (!sourceFiles.empty()) { sourceBuildPhase = this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase); @@ -1039,9 +1037,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( sourceBuildPhase->AddAttribute("buildActionMask", this->CreateString("2147483647")); buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (std::vector::iterator i = sourceFiles.begin(); - i != sourceFiles.end(); ++i) { - buildFiles->AddObject(*i); + for (auto& sourceFile : sourceFiles) { + buildFiles->AddObject(sourceFile); } sourceBuildPhase->AddAttribute("files", buildFiles); sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", @@ -1049,7 +1046,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( } // create header build phase - only for framework targets - cmXCodeObject* headerBuildPhase = 0; + cmXCodeObject* headerBuildPhase = nullptr; if (!headerFiles.empty() && isFrameworkTarget) { headerBuildPhase = this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase); @@ -1057,9 +1054,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( headerBuildPhase->AddAttribute("buildActionMask", this->CreateString("2147483647")); buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (std::vector::iterator i = headerFiles.begin(); - i != headerFiles.end(); ++i) { - buildFiles->AddObject(*i); + for (auto& headerFile : headerFiles) { + buildFiles->AddObject(headerFile); } headerBuildPhase->AddAttribute("files", buildFiles); headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", @@ -1067,7 +1063,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( } // create resource build phase - only for framework or bundle targets - cmXCodeObject* resourceBuildPhase = 0; + cmXCodeObject* resourceBuildPhase = nullptr; if (!resourceFiles.empty() && (isFrameworkTarget || isBundleTarget || isCFBundleTarget)) { resourceBuildPhase = @@ -1076,9 +1072,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( resourceBuildPhase->AddAttribute("buildActionMask", this->CreateString("2147483647")); buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (std::vector::iterator i = resourceFiles.begin(); - i != resourceFiles.end(); ++i) { - buildFiles->AddObject(*i); + for (auto& resourceFile : resourceFiles) { + buildFiles->AddObject(resourceFile); } resourceBuildPhase->AddAttribute("files", buildFiles); resourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", @@ -1089,7 +1084,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( // framework or bundle targets std::vector contentBuildPhases; if (isFrameworkTarget || isBundleTarget || isCFBundleTarget) { - typedef std::map > + typedef std::map> mapOfVectorOfSourceFiles; mapOfVectorOfSourceFiles bundleFiles; for (std::vector::const_iterator i = classes.begin(); @@ -1140,7 +1135,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( // create vector of "resource content file" build phases - only for // framework or bundle targets if (isFrameworkTarget || isBundleTarget || isCFBundleTarget) { - typedef std::map > + typedef std::map> mapOfVectorOfSourceFiles; mapOfVectorOfSourceFiles bundleFiles; for (std::vector::const_iterator i = classes.begin(); @@ -1177,7 +1172,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( } // create framework build phase - cmXCodeObject* frameworkBuildPhase = 0; + cmXCodeObject* frameworkBuildPhase = nullptr; if (!externalObjFiles.empty()) { frameworkBuildPhase = this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase); @@ -1186,9 +1181,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( this->CreateString("2147483647")); buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); frameworkBuildPhase->AddAttribute("files", buildFiles); - for (std::vector::iterator i = externalObjFiles.begin(); - i != externalObjFiles.end(); ++i) { - buildFiles->AddObject(*i); + for (auto& externalObjFile : externalObjFiles) { + buildFiles->AddObject(externalObjFile); } frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", this->CreateString("0")); @@ -1209,14 +1203,13 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets( void cmGlobalXCodeGenerator::ForceLinkerLanguages() { - for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - std::vector tgts = - this->LocalGenerators[i]->GetGeneratorTargets(); + for (auto& localGenerator : this->LocalGenerators) { + const std::vector& tgts = + localGenerator->GetGeneratorTargets(); // All targets depend on the build-system check target. - for (std::vector::const_iterator ti = tgts.begin(); - ti != tgts.end(); ++ti) { + for (auto tgt : tgts) { // This makes sure all targets link using the proper language. - this->ForceLinkerLanguage(*ti); + this->ForceLinkerLanguage(tgt); } } } @@ -1237,9 +1230,8 @@ 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::const_iterator li = impl->Languages.begin(); - li != impl->Languages.end(); ++li) { - if (*li == llang) { + for (auto const& Language : impl->Languages) { + if (Language == llang) { return; } } @@ -1277,8 +1269,8 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateBuildPhase( const char* name, const char* name2, cmGeneratorTarget* target, const std::vector& 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); @@ -1465,7 +1457,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; @@ -1541,16 +1533,15 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( makefileStream << "all: "; std::map tname; int count = 0; - for (std::vector::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& outputs = ccg.GetOutputs(); if (!outputs.empty()) { - for (std::vector::const_iterator o = outputs.begin(); - o != outputs.end(); ++o) { + for (auto const& output : outputs) { makefileStream << "\\\n\t" - << this->ConvertToRelativeForMake(o->c_str()); + << this->ConvertToRelativeForMake(output.c_str()); } } else { std::ostringstream str; @@ -1561,18 +1552,18 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( } } makefileStream << "\n\n"; - for (std::vector::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& outputs = ccg.GetOutputs(); if (!outputs.empty()) { // There is at least one output, start the rule for it const char* sep = ""; - for (std::vector::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.c_str()); sep = " "; } makefileStream << ": "; @@ -1580,11 +1571,9 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile( // There are no outputs. Use the generated force rule name. makefileStream << tname[&ccg.GetCC()] << ": "; } - for (std::vector::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()); @@ -1639,9 +1628,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, std::set languages; gtgt->GetLanguages(languages, configName); std::map cflags; - for (std::set::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. @@ -1737,9 +1724,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, } else { cmXCodeObject* archObjects = this->CreateObject(cmXCodeObject::OBJECT_LIST); - for (std::vector::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 +1740,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; @@ -1964,10 +1950,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, std::set emitted; emitted.insert("/System/Library/Frameworks"); - for (std::vector::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) { @@ -1980,9 +1965,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, } } } else { - std::string incpath = this->XCodeEscapePath(*i); + std::string incpath = this->XCodeEscapePath(include); if (emitSystemIncludes && - gtgt->IsSystemIncludeDirectory(*i, configName)) { + gtgt->IsSystemIncludeDirectory(include, configName)) { sysdirs.Add(incpath); } else { dirs.Add(incpath); @@ -1992,12 +1977,11 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // Add framework search paths needed for linking. if (cmComputeLinkInformation* cli = gtgt->GetLinkInformation(configName)) { std::vector const& fwDirs = cli->GetFrameworkPaths(); - for (std::vector::const_iterator fdi = fwDirs.begin(); - fdi != fwDirs.end(); ++fdi) { - if (emitted.insert(*fdi).second) { - std::string incpath = this->XCodeEscapePath(*fdi); + for (auto const& fwDir : fwDirs) { + if (emitted.insert(fwDir).second) { + std::string incpath = this->XCodeEscapePath(fwDir); if (emitSystemIncludes && - gtgt->IsSystemIncludeDirectory(*fdi, configName)) { + gtgt->IsSystemIncludeDirectory(fwDir, configName)) { sysfdirs.Add(incpath); } else { fdirs.Add(incpath); @@ -2025,27 +2009,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::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 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::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,10 +2052,9 @@ 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::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")) { @@ -2090,25 +2071,24 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, this->CreateString("NO")); buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN", this->CreateString("NO")); - for (std::set::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: @@ -2225,15 +2205,14 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // Convert "XCODE_ATTRIBUTE_*" properties directly. { std::vector const& props = gtgt->GetPropertyKeys(); - for (std::vector::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 : props) { + 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 +2247,8 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateUtilityTarget( target->SetComment(gtgt->GetName()); cmXCodeObject* buildPhases = this->CreateObject(cmXCodeObject::OBJECT_LIST); std::vector 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); @@ -2283,7 +2262,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateUtilityTarget( if (gtgt->GetType() == cmStateEnums::UTILITY) { std::vector sources; if (!gtgt->GetConfigCommonSourceFiles(sources)) { - return 0; + return nullptr; } for (std::vector::const_iterator i = sources.begin(); @@ -2321,15 +2300,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 +2328,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 +2346,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 +2362,7 @@ const char* cmGlobalXCodeGenerator::GetTargetFileType( default: break; } - return 0; + return nullptr; } const char* cmGlobalXCodeGenerator::GetTargetProductType( @@ -2401,12 +2380,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 +2398,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 +2449,13 @@ cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget( cmGeneratorTarget const* t) { if (!t) { - return 0; + return nullptr; } std::map::const_iterator const i = this->XCodeObjectMap.find(t); if (i == this->XCodeObjectMap.end()) { - return 0; + return nullptr; } return i->second; } @@ -2560,15 +2540,14 @@ void cmGlobalXCodeGenerator::AppendBuildSettingAttribute( std::vector list = buildConfigs->GetObjectList(); // each configuration and the target itself has a buildSettings in it // list.push_back(target); - for (std::vector::iterator i = list.begin(); i != list.end(); - ++i) { + for (auto& i : list) { if (!configName.empty()) { - if ((*i)->GetObject("name")->GetString() == configName) { - cmXCodeObject* settings = (*i)->GetObject("buildSettings"); + if (i->GetObject("name")->GetString() == configName) { + cmXCodeObject* settings = i->GetObject("buildSettings"); this->AppendOrAddBuildSetting(settings, attribute, value); } } else { - cmXCodeObject* settings = (*i)->GetObject("buildSettings"); + cmXCodeObject* settings = i->GetObject("buildSettings"); this->AppendOrAddBuildSetting(settings, attribute, value); } } @@ -2587,20 +2566,15 @@ 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 (auto dep : deps) { + if (cmXCodeObject* dptarget = this->FindXCodeTarget(dep)) { this->AddDependTarget(target, dptarget); } } // Loop over configuration types and set per-configuration info. - for (std::vector::iterator i = - this->CurrentConfigurationTypes.begin(); - i != this->CurrentConfigurationTypes.end(); ++i) { + for (auto const& configName : this->CurrentConfigurationTypes) { // Get the current configuration name. - std::string configName = *i; - if (this->XcodeVersion >= 50) { // Add object library contents as link flags. std::string linkObjs; @@ -2636,9 +2610,8 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) // Add dependencies directly on library files. { std::vector const& libDeps = cli.GetDepends(); - for (std::vector::const_iterator j = libDeps.begin(); - j != libDeps.end(); ++j) { - target->AddDependLibrary(configName, *j); + for (auto const& libDep : libDeps) { + target->AddDependLibrary(configName, libDep); } } @@ -2646,16 +2619,15 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) { std::vector const& libDirs = cli.GetDirectories(); std::string linkDirs; - for (std::vector::const_iterator libDir = libDirs.begin(); - libDir != libDirs.end(); ++libDir) { - if (libDir->size() && *libDir != "/usr/lib") { + for (auto const& libDir : libDirs) { + 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", @@ -2668,18 +2640,18 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) 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 : libNames) { 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,15 +2663,12 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) bool cmGlobalXCodeGenerator::CreateGroups( std::vector& generators) { - for (std::vector::iterator i = generators.begin(); - i != generators.end(); ++i) { - cmMakefile* mf = (*i)->GetMakefile(); + for (auto& generator : generators) { + cmMakefile* mf = generator->GetMakefile(); std::vector sourceGroups = mf->GetSourceGroups(); - std::vector tgts = (*i)->GetGeneratorTargets(); - for (std::vector::iterator l = tgts.begin(); - l != tgts.end(); l++) { - cmGeneratorTarget* gtgt = *l; - + const std::vector& tgts = + generator->GetGeneratorTargets(); + for (auto gtgt : tgts) { // Same skipping logic here as in CreateXCodeTargets so that we do not // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source // groups: @@ -2723,10 +2692,8 @@ bool cmGlobalXCodeGenerator::CreateGroups( gtgt->GetAllConfigSources(); // Put cmSourceFile instances in proper groups: - for (std::vector::const_iterator si = - sources.begin(); - si != sources.end(); ++si) { - cmSourceFile const* sf = si->Source; + for (auto const& si : sources) { + cmSourceFile const* sf = si.Source; if (this->XcodeVersion >= 50 && !sf->GetObjectLibrary().empty()) { // Object library files go on the link line instead. continue; @@ -2745,19 +2712,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("")); - if (parentChildren) + if (parentChildren) { parentChildren->AddObject(group); + } return group; } @@ -2781,7 +2750,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,7 +2780,7 @@ 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 (std::string(sg->GetFullName()).empty()) { this->GroupNameMap[s] = tgroup; return tgroup; } @@ -2822,13 +2791,13 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup( cmSystemTools::tokenize(sg->GetFullName(), "\\"); std::string curr_folder = target; curr_folder += "/"; - for (std::vector::size_type i = 0; i < folders.size(); i++) { - curr_folder += folders[i]; + for (auto const& folder : folders) { + curr_folder += folder; std::map::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 +2816,15 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( cmLocalGenerator* root, std::vector& 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 (auto& CurrentConfigurationType : this->CurrentConfigurationTypes) { cmXCodeObject* buildStyle = this->CreateObject(cmXCodeObject::PBXBuildStyle); - const char* name = this->CurrentConfigurationTypes[i].c_str(); + const char* name = CurrentConfigurationType.c_str(); buildStyle->AddAttribute("name", this->CreateString(name)); buildStyle->SetComment(name); cmXCodeObject* sgroup = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); @@ -2888,7 +2857,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 +2873,16 @@ 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) + if (this->XcodeVersion >= 32) { this->RootObject->AddAttribute("compatibilityVersion", this->CreateString("Xcode 3.2")); - else if (this->XcodeVersion >= 31) + } else if (this->XcodeVersion >= 31) { this->RootObject->AddAttribute("compatibilityVersion", this->CreateString("Xcode 3.1")); - else + } else { this->RootObject->AddAttribute("compatibilityVersion", this->CreateString("Xcode 3.0")); + } // Point Xcode at the top of the source tree. { std::string pdir = @@ -2924,7 +2894,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( this->CreateObject(cmXCodeObject::XCConfigurationList); cmXCodeObject* buildConfigurations = this->CreateObject(cmXCodeObject::OBJECT_LIST); - typedef std::vector > Configs; + typedef std::vector> Configs; Configs configs; const char* defaultConfigName = "Debug"; for (unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i) { @@ -2937,8 +2907,8 @@ 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); + for (auto& config : configs) { + buildConfigurations->AddObject(config.second); } configlist->AddAttribute("buildConfigurations", buildConfigurations); @@ -2996,7 +2966,7 @@ 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 @@ -3006,43 +2976,38 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( d != vars.end(); ++d) { if (d->find("CMAKE_XCODE_ATTRIBUTE_") == 0) { std::string attribute = d->substr(22); - this->FilterConfigurationAttribute(i->first, attribute); + this->FilterConfigurationAttribute(config.first, attribute); if (!attribute.empty()) { cmGeneratorExpression ge; std::string processed = ge.Parse(this->CurrentMakefile->GetDefinition(*d)) - ->Evaluate(this->CurrentLocalGenerator, i->first); + ->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 targets; - for (std::vector::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::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::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) { @@ -3135,9 +3100,7 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( this->CurrentConfigurationTypes.begin(); ct != this->CurrentConfigurationTypes.end(); ++ct) { std::string configName = *ct; - for (std::vector::iterator i = targets.begin(); - i != targets.end(); ++i) { - cmXCodeObject* target = *i; + for (auto target : targets) { cmGeneratorTarget* gt = target->GetTarget(); if (gt->GetType() == cmStateEnums::EXECUTABLE || @@ -3162,9 +3125,8 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( target->GetDependTargets().find(*ct); if (y != target->GetDependTargets().end()) { std::vector const& deptgts = y->second; - for (std::vector::const_iterator d = deptgts.begin(); - d != deptgts.end(); ++d) { - makefileStream << this->PostBuildMakeTarget(*d, *ct) << ": " + for (auto const& deptgt : deptgts) { + makefileStream << this->PostBuildMakeTarget(deptgt, *ct) << ": " << trel << "\n"; } } @@ -3186,9 +3148,8 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( target->GetDependLibraries().find(*ct); if (x != target->GetDependLibraries().end()) { std::vector const& deplibs = x->second; - for (std::vector::const_iterator d = deplibs.begin(); - d != deplibs.end(); ++d) { - std::string file = this->ConvertToRelativeForMake(d->c_str()); + for (auto const& deplib : deplibs) { + std::string file = this->ConvertToRelativeForMake(deplib.c_str()); makefileStream << "\\\n\t" << file; dummyRules.insert(file); } @@ -3220,11 +3181,9 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( if (this->Architectures.size() > 1) { std::string universal = this->GetObjectsNormalDirectory( this->CurrentProject, configName, gt); - for (std::vector::iterator arch = - this->Architectures.begin(); - arch != this->Architectures.end(); ++arch) { + for (auto& architecture : this->Architectures) { std::string universalFile = universal; - universalFile += *arch; + universalFile += architecture; universalFile += "/"; universalFile += gt->GetFullName(configName); makefileStream << "\t/bin/rm -f " @@ -3241,22 +3200,20 @@ 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::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& generators) { - if (generators.size() == 0) { + if (generators.empty()) { return; } // Skip local generators that are excluded from this project. - for (std::vector::iterator g = generators.begin(); - g != generators.end(); ++g) { - if (this->IsExcluded(root, *g)) { + for (auto& generator : generators) { + if (this->IsExcluded(root, generator)) { continue; } } @@ -3298,6 +3255,31 @@ void cmGlobalXCodeGenerator::OutputXCodeProject( void cmGlobalXCodeGenerator::OutputXCodeSharedSchemes( const std::string& xcProjDir) { + // collect all tests for the targets + std::map testables; + + for (std::vector::const_iterator i = + this->XCodeObjects.begin(); + i != this->XCodeObjects.end(); ++i) { + cmXCodeObject* obj = *i; + 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 for (std::vector::const_iterator i = this->XCodeObjects.begin(); i != this->XCodeObjects.end(); ++i) { @@ -3305,8 +3287,9 @@ void cmGlobalXCodeGenerator::OutputXCodeSharedSchemes( if (obj->GetType() == cmXCodeObject::OBJECT && (obj->GetIsA() == cmXCodeObject::PBXNativeTarget || obj->GetIsA() == cmXCodeObject::PBXAggregateTarget)) { - cmXCodeScheme schm(obj, this->CurrentConfigurationTypes, - this->XcodeVersion); + const std::string& targetName = obj->GetTarget()->GetName(); + cmXCodeScheme schm(obj, testables[targetName], + this->CurrentConfigurationTypes, this->XcodeVersion); schm.WriteXCodeSharedScheme(xcProjDir, this->RelativeToSource(xcProjDir.c_str())); } @@ -3358,12 +3341,13 @@ void cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout, cmXCodeObject::Indent(1, fout); fout << "};\n"; cmXCodeObject::Indent(1, fout); - if (this->XcodeVersion >= 32) + if (this->XcodeVersion >= 32) { fout << "objectVersion = 46;\n"; - else if (this->XcodeVersion >= 31) + } else if (this->XcodeVersion >= 31) { fout << "objectVersion = 45;\n"; - else + } else { fout << "objectVersion = 44;\n"; + } cmXCode21Object::PrintList(this->XCodeObjects, fout); cmXCodeObject::Indent(1, fout); fout << "rootObject = " << this->RootObject->GetId() @@ -3483,11 +3467,10 @@ void cmGlobalXCodeGenerator::AppendDefines( { // GCC_PREPROCESSOR_DEFINITIONS is a space-separated list of definitions. std::string def; - for (std::vector::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; @@ -3572,7 +3555,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; diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index e69793bcc..e9ca91ce4 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 #include @@ -37,7 +37,7 @@ public: static cmGlobalGeneratorFactory* NewFactory(); ///! Get the name for the generator. - std::string GetName() const CM_OVERRIDE + std::string GetName() const override { return cmGlobalXCodeGenerator::GetActualName(); } @@ -47,14 +47,14 @@ public: static void GetDocumentation(cmDocumentationEntry& entry); ///! Create a local generator appropriate to this Global Generator - 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 const& languages, cmMakefile*, - bool optional) CM_OVERRIDE; + bool optional) override; /** * Try running cmake and building a file. This is used for dynalically * loaded commands, not as part of the usual build process. @@ -66,47 +66,48 @@ public: const std::string& targetName, const std::string& config, bool fast, bool verbose, std::vector const& makeOptions = - std::vector()) CM_OVERRIDE; + std::vector()) 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; + 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 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; + bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) override; void AppendFlag(std::string& flags, std::string const& flag); protected: - void AddExtraIDETargets() CM_OVERRIDE; - void Generate() CM_OVERRIDE; + void AddExtraIDETargets() override; + 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& generators); std::string XCodeEscapePath(const std::string& p); std::string RelativeToSource(const char* p); @@ -144,7 +145,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); @@ -219,11 +220,11 @@ private: std::vector 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,7 +239,7 @@ private: bool XcodeBuildCommandInitialized; void PrintCompilerAdvice(std::ostream&, std::string const&, - const char*) const CM_OVERRIDE + const char*) const override { } diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 7e953cef1..dd2993d70 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 #include +#include // IWYU pragma: keep #include #include @@ -15,10 +16,20 @@ #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"; + +const char* getShapeForTarget(const cmGeneratorTarget* target) { if (!target) { return "ellipse"; @@ -40,6 +51,76 @@ static const char* getShapeForTarget(const cmGeneratorTarget* target) return "box"; } +std::map getScopedLinkLibrariesFromTarget( + cmTarget* Target) +{ + char sep = ';'; + std::map 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 (std::string::npos == element.find("$& localGenerators) : GraphType("digraph") @@ -66,8 +147,8 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator ggi(&cm); - CM_AUTO_PTR mf(new cmMakefile(&ggi, cm.GetCurrentSnapshot())); - CM_AUTO_PTR lg(ggi.CreateLocalGenerator(mf.get())); + cmMakefile mf(&ggi, cm.GetCurrentSnapshot()); + std::unique_ptr lg(ggi.CreateLocalGenerator(&mf)); const char* inFileName = settingsFileName; @@ -78,7 +159,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, } } - if (!mf->ReadListFile(inFileName)) { + if (!mf.ReadListFile(inFileName)) { cmSystemTools::Error("Problem opening GraphViz options file: ", inFileName); return; @@ -88,7 +169,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, #define __set_if_set(var, cmakeDefinition) \ { \ - const char* value = mf->GetDefinition(cmakeDefinition); \ + const char* value = mf.GetDefinition(cmakeDefinition); \ if (value) { \ (var) = value; \ } \ @@ -101,9 +182,9 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, #define __set_bool_if_set(var, cmakeDefinition) \ { \ - const char* value = mf->GetDefinition(cmakeDefinition); \ + const char* value = mf.GetDefinition(cmakeDefinition); \ if (value) { \ - (var) = mf->IsOn(cmakeDefinition); \ + (var) = mf.IsOn(cmakeDefinition); \ } \ } @@ -123,10 +204,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, std::vector ignoreTargetsRegExVector; cmSystemTools::ExpandListArgument(ignoreTargetsRegexes, ignoreTargetsRegExVector); - for (std::vector::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())) { std::cerr << "Could not compile bad regex \"" << currentRegexString @@ -147,20 +225,18 @@ void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName) this->CollectTargetsAndLibs(); - for (std::map::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()); @@ -174,7 +250,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); @@ -191,14 +267,12 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName) this->CollectTargetsAndLibs(); - for (std::map::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,7 +281,7 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName) std::string currentFilename = fileName; currentFilename += "."; - currentFilename += ptrIt->first; + currentFilename += ptr.first; cmGeneratedFileStream str(currentFilename.c_str()); if (!str) { return; @@ -216,8 +290,7 @@ 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); } } @@ -237,19 +310,16 @@ void cmGraphVizWriter::WriteGlobalFile(const char* fileName) std::set insertedConnections; std::set insertedNodes; - for (std::map::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 +349,17 @@ 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 ll = + getScopedLinkLibrariesFromTarget(targetPtrIt->second->Target); - 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 char* libName = llit.first.c_str(); std::map::const_iterator libNameIt = this->TargetNamesNodes.find(libName); @@ -310,6 +378,18 @@ void cmGraphVizWriter::WriteConnections( insertedNodes, str); str << " \"" << myNodeName << "\" -> \"" << libNameIt->second << "\""; + + switch (llit.second) { + case LLT_SCOPE_PRIVATE: + str << "[style = " << GRAPHVIZ_PRIVATE_EDEGE_STYLE << "]"; + break; + case LLT_SCOPE_INTERFACE: + str << "[style = " << GRAPHVIZ_INTERFACE_EDEGE_STYLE << "]"; + break; + default: + break; + } + str << " // " << targetName << " -> " << libName << std::endl; this->WriteConnections(libName, insertedNodes, insertedConnections, str); } @@ -330,7 +410,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 +418,26 @@ void cmGraphVizWriter::WriteDependerConnections( std::string myNodeName = this->TargetNamesNodes.find(targetName)->second; // now search who links against me - for (std::map::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()); + &(tptr.second->Target->GetOriginalLinkLibraries()); - for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin(); - llit != ll->end(); ++llit) { - std::string libName = llit->first; + for (auto const& llit : *ll) { + std::string libName = llit.first; if (libName == targetName) { // So this target links against targetName. std::map::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 +447,12 @@ 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; + this->WriteDependerConnections(tptr.first, insertedNodes, insertedConnections, str); } } @@ -417,13 +492,10 @@ int cmGraphVizWriter::CollectAllTargets() { int cnt = 0; // First pass get the list of all cmake targets - for (std::vector::const_iterator lit = - this->LocalGenerators.begin(); - lit != this->LocalGenerators.end(); ++lit) { - std::vector targets = (*lit)->GetGeneratorTargets(); - for (std::vector::const_iterator it = targets.begin(); - it != targets.end(); ++it) { - const char* realTargetName = (*it)->GetName().c_str(); + for (cmLocalGenerator* lg : this->LocalGenerators) { + const std::vector& targets = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { + const char* realTargetName = target->GetName().c_str(); if (this->IgnoreThisTarget(realTargetName)) { // Skip ignored targets continue; @@ -432,7 +504,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,22 +514,18 @@ 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::const_iterator lit = - this->LocalGenerators.begin(); - lit != this->LocalGenerators.end(); ++lit) { - std::vector targets = (*lit)->GetGeneratorTargets(); - for (std::vector::const_iterator it = targets.begin(); - it != targets.end(); ++it) { - const char* realTargetName = (*it)->GetName().c_str(); + for (cmLocalGenerator* lg : this->LocalGenerators) { + const std::vector& targets = lg->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { + const char* realTargetName = target->GetName().c_str(); 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) { + const char* libName = llit.first.c_str(); if (this->IgnoreThisTarget(libName)) { // Skip ignored targets continue; @@ -469,7 +537,7 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt) 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 +549,7 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt) bool cmGraphVizWriter::IgnoreThisTarget(const std::string& name) { - for (std::vector::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; diff --git a/Source/cmHexFileConverter.cxx b/Source/cmHexFileConverter.cxx index 78dceb794..8deb8c183 100644 --- a/Source/cmHexFileConverter.cxx +++ b/Source/cmHexFileConverter.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmHexFileConverter.h" -#include "cmConfigure.h" #include #include @@ -22,7 +21,7 @@ static bool cm_IsHexChar(char c) static unsigned int ChompStrlen(const char* line) { - if (line == CM_NULLPTR) { + if (line == nullptr) { return 0; } unsigned int length = static_cast(strlen(line)); @@ -139,7 +138,7 @@ cmHexFileConverter::FileType cmHexFileConverter::DetermineFileType( { char buf[1024]; FILE* inFile = cmsys::SystemTools::Fopen(inFileName, "rb"); - if (inFile == CM_NULLPTR) { + if (inFile == nullptr) { return Binary; } @@ -188,11 +187,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 +200,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..25278e4a3 100644 --- a/Source/cmHexFileConverter.h +++ b/Source/cmHexFileConverter.h @@ -3,6 +3,8 @@ #ifndef cmHexFileConverter_h #define cmHexFileConverter_h +#include "cmConfigure.h" // IWYU pragma: keep + /** \class cmHexFileConverter * \brief Can detects Intel Hex and Motorola S-record files and convert them * to binary files. diff --git a/Source/cmIDEOptions.h b/Source/cmIDEOptions.h index 19e96bd44..af0312874 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 #include diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 0972664a2..4926f22d0 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -8,17 +8,17 @@ #include "cmMakefile.h" #include "cmOutputConverter.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" +#include // IWYU pragma: keep + static std::string cmIfCommandError( std::vector const& args) { std::string err = "given arguments:\n "; - for (std::vector::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; @@ -37,7 +37,8 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, // 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 fb(mf.RemoveFunctionBlocker(this, lff)); + std::unique_ptr fb( + mf.RemoveFunctionBlocker(this, lff)); if (!fb.get()) { return false; } @@ -45,21 +46,20 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, // 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 (!cmSystemTools::Strucmp(func.Name.c_str(), "if")) { scopeDepth++; } - if (!cmSystemTools::Strucmp(this->Functions[c].Name.c_str(), - "endif")) { + if (!cmSystemTools::Strucmp(func.Name.c_str(), "endif")) { scopeDepth--; } // watch for our state change if (scopeDepth == 0 && - !cmSystemTools::Strucmp(this->Functions[c].Name.c_str(), "else")) { + !cmSystemTools::Strucmp(func.Name.c_str(), "else")) { if (this->ElseSeen) { - cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]); + cmListFileBacktrace bt = mf.GetBacktrace(func); mf.GetCMakeInstance()->IssueMessage( cmake::FATAL_ERROR, "A duplicate ELSE command was found inside an IF block.", bt); @@ -74,13 +74,12 @@ 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")) { + !cmSystemTools::Strucmp(func.Name.c_str(), "elseif")) { if (this->ElseSeen) { - cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]); + cmListFileBacktrace bt = mf.GetBacktrace(func); mf.GetCMakeInstance()->IssueMessage( cmake::FATAL_ERROR, "An ELSEIF command was found after an ELSE command.", bt); @@ -93,23 +92,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 expandedArguments; - mf.ExpandArguments(this->Functions[c].Arguments, - expandedArguments); + mf.ExpandArguments(func.Arguments, expandedArguments); cmake::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,7 +115,7 @@ 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) { cmSystemTools::SetFatalErrorOccured(); @@ -135,7 +133,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; diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h index 5877a7d12..e3d30ddbd 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 #include @@ -25,10 +25,10 @@ public: this->ElseSeen = false; this->ScopeDepth = 0; } - ~cmIfFunctionBlocker() CM_OVERRIDE {} + ~cmIfFunctionBlocker() 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 Args; std::vector Functions; @@ -45,21 +45,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& args, - cmExecutionStatus&) CM_OVERRIDE; + cmExecutionStatus&) override; /** * This is called when the command is first encountered in * the CMakeLists.txt file. */ bool InitialPass(std::vector const&, - cmExecutionStatus&) CM_OVERRIDE + cmExecutionStatus&) override { return false; } diff --git a/Source/cmIncludeCommand.cxx b/Source/cmIncludeCommand.cxx index 12e0c9ab3..cd4d85030 100644 --- a/Source/cmIncludeCommand.cxx +++ b/Source/cmIncludeCommand.cxx @@ -78,7 +78,7 @@ bool cmIncludeCommand::InitialPass(std::vector 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; 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx index b81f7cb2d..4c3060797 100644 --- a/Source/cmIncludeDirectoryCommand.cxx +++ b/Source/cmIncludeDirectoryCommand.cxx @@ -116,7 +116,7 @@ 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; } 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; protected: // used internally diff --git a/Source/cmIncludeExternalMSProjectCommand.cxx b/Source/cmIncludeExternalMSProjectCommand.cxx index 03388c7e9..bd16b1d92 100644 --- a/Source/cmIncludeExternalMSProjectCommand.cxx +++ b/Source/cmIncludeExternalMSProjectCommand.cxx @@ -91,9 +91,8 @@ bool cmIncludeExternalMSProjectCommand::InitialPass( if (!platformMapping.empty()) target->SetProperty("VS_PLATFORM_MAPPING", platformMapping.c_str()); - for (std::vector::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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmIncludeGuardCommand.cxx b/Source/cmIncludeGuardCommand.cxx new file mode 100644 index 000000000..505b07cad --- /dev/null +++ b/Source/cmIncludeGuardCommand.cxx @@ -0,0 +1,108 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmIncludeGuardCommand.h" + +#include "cmExecutionStatus.h" +#include "cmMakefile.h" +#include "cmStateDirectory.h" +#include "cmStateSnapshot.h" +#include "cmSystemTools.h" +#include "cmake.h" + +namespace { + +enum IncludeGuardScope +{ + VARIABLE, + DIRECTORY, + GLOBAL +}; + +std::string GetIncludeGuardVariableName(std::string const& filePath) +{ + std::string result = "__INCGUARD_"; +#ifdef CMAKE_BUILD_WITH_CMAKE + result += cmSystemTools::ComputeStringMD5(filePath); +#else + result += cmSystemTools::MakeCidentifier(filePath); +#endif + result += "__"; + return result; +} + +bool CheckIncludeGuardIsSet(cmMakefile* mf, std::string const& includeGuardVar) +{ + if (mf->GetProperty(includeGuardVar)) { + return true; + } + cmStateSnapshot dirSnapshot = + mf->GetStateSnapshot().GetBuildsystemDirectoryParent(); + while (dirSnapshot.GetState()) { + cmStateDirectory stateDir = dirSnapshot.GetDirectory(); + if (stateDir.GetProperty(includeGuardVar)) { + return true; + } + dirSnapshot = dirSnapshot.GetBuildsystemDirectoryParent(); + } + return false; +} + +} // anonymous namespace + +// cmIncludeGuardCommand +bool cmIncludeGuardCommand::InitialPass(std::vector const& args, + cmExecutionStatus& status) +{ + if (args.size() > 1) { + this->SetError( + "given an invalid number of arguments. The command takes at " + "most 1 argument."); + return false; + } + + IncludeGuardScope scope = VARIABLE; + + if (!args.empty()) { + std::string const& arg = args[0]; + if (arg == "DIRECTORY") { + scope = DIRECTORY; + } else if (arg == "GLOBAL") { + scope = GLOBAL; + } else { + this->SetError("given an invalid scope: " + arg); + return false; + } + } + + std::string includeGuardVar = GetIncludeGuardVariableName( + this->Makefile->GetDefinition("CMAKE_CURRENT_LIST_FILE")); + + cmMakefile* const mf = this->Makefile; + + switch (scope) { + case VARIABLE: + if (mf->IsDefinitionSet(includeGuardVar)) { + status.SetReturnInvoked(); + return true; + } + mf->AddDefinition(includeGuardVar, true); + break; + case DIRECTORY: + if (CheckIncludeGuardIsSet(mf, includeGuardVar)) { + status.SetReturnInvoked(); + return true; + } + mf->SetProperty(includeGuardVar, "TRUE"); + break; + case GLOBAL: + cmake* const cm = mf->GetCMakeInstance(); + if (cm->GetProperty(includeGuardVar)) { + status.SetReturnInvoked(); + return true; + } + cm->SetProperty(includeGuardVar, "TRUE"); + break; + } + + return true; +} diff --git a/Source/cmIncludeGuardCommand.h b/Source/cmIncludeGuardCommand.h new file mode 100644 index 000000000..eaad9b89a --- /dev/null +++ b/Source/cmIncludeGuardCommand.h @@ -0,0 +1,37 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmIncludeGuardCommand_h +#define cmIncludeGuardCommand_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include +#include + +#include "cmCommand.h" + +class cmExecutionStatus; + +/** \class cmIncludeGuardCommand + * \brief cmIncludeGuardCommand identical to C++ #pragma_once command + * Can work in 3 modes: GLOBAL (works on global properties), + * DIRECTORY(use directory property), VARIABLE(unnamed overload without + * arguments) define an ordinary variable to be used as include guard checker + */ +class cmIncludeGuardCommand : public cmCommand +{ +public: + /** + * This is a virtual constructor for the command. + */ + cmCommand* Clone() override { return new cmIncludeGuardCommand; } + + /** + * This is called when the command is first encountered in + * the CMakeLists.txt file. + */ + bool InitialPass(std::vector const& args, + 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 294fb178d..685fc671c 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -141,23 +141,23 @@ bool cmInstallCommand::HandleScriptMode(std::vector 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]; + std::string script = arg; if (!cmSystemTools::FileIsFullPath(script.c_str())) { 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 +167,7 @@ bool cmInstallCommand::HandleScriptMode(std::vector 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)); } @@ -204,7 +204,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) cmCommandArgumentsHelper argHelper; cmCommandArgumentGroup group; - cmCAStringVector genericArgVector(&argHelper, CM_NULLPTR); + cmCAStringVector genericArgVector(&argHelper, nullptr); cmCAStringVector archiveArgVector(&argHelper, "ARCHIVE", &group); cmCAStringVector libraryArgVector(&argHelper, "LIBRARY", &group); cmCAStringVector runtimeArgVector(&argHelper, "RUNTIME", &group); @@ -216,10 +216,10 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) &group); cmCAStringVector publicHeaderArgVector(&argHelper, "PUBLIC_HEADER", &group); cmCAStringVector resourceArgVector(&argHelper, "RESOURCE", &group); - genericArgVector.Follows(CM_NULLPTR); + genericArgVector.Follows(nullptr); group.Follows(&genericArgVector); - argHelper.Parse(&args, CM_NULLPTR); + argHelper.Parse(&args, nullptr); // now parse the generic args (i.e. the ones not specialized on LIBRARY/ // ARCHIVE, RUNTIME etc. (see above) @@ -229,7 +229,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) cmCAStringVector targetList(&genericArgs.Parser, "TARGETS"); cmCAString exports(&genericArgs.Parser, "EXPORT", &genericArgs.ArgumentGroup); - targetList.Follows(CM_NULLPTR); + targetList.Follows(nullptr); genericArgs.ArgumentGroup.Follows(&targetList); genericArgs.Parse(&genericArgVector.GetVector(), &unknownArgs); bool success = genericArgs.Finalize(); @@ -336,19 +336,16 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) (this->Makefile->IsOn("WIN32") || this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")); - for (std::vector::const_iterator targetIt = - targetList.GetVector().begin(); - targetIt != targetList.GetVector().end(); ++targetIt) { + for (std::string const& tgt : targetList.GetVector()) { - 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)) { + if (cmTarget* target = this->Makefile->FindLocalNonAliasTarget(tgt)) { // Found the target. Check its type. if (target->GetType() != cmStateEnums::EXECUTABLE && target->GetType() != cmStateEnums::STATIC_LIBRARY && @@ -357,7 +354,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector 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; @@ -367,7 +364,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) if (!this->Makefile->GetGlobalGenerator()->HasKnownObjectFileLocation( &reason)) { std::ostringstream e; - e << "TARGETS given OBJECT library \"" << (*targetIt) + e << "TARGETS given OBJECT library \"" << tgt << "\" which may not be installed" << reason << "."; this->SetError(e.str()); return false; @@ -378,7 +375,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) } else { // Did not find the target. std::ostringstream e; - e << "TARGETS given target \"" << (*targetIt) + e << "TARGETS given target \"" << tgt << "\" which does not exist in this directory."; this->SetError(e.str()); return false; @@ -398,19 +395,18 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) bool installsResource = false; // Generate install script code to install the given targets. - for (std::vector::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* 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; @@ -437,8 +433,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) runtimeGenerator = CreateInstallTargetGenerator(target, runtimeArgs, false); } - if ((archiveGenerator == CM_NULLPTR) && - (runtimeGenerator == CM_NULLPTR)) { + if ((archiveGenerator == nullptr) && (runtimeGenerator == nullptr)) { this->SetError("Library TARGETS given no DESTINATION!"); return false; } @@ -688,16 +683,16 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) } // 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; + 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); @@ -779,7 +774,7 @@ bool cmInstallCommand::HandleFilesMode(std::vector const& args) bool programs = (args[0] == "PROGRAMS"); cmInstallCommandArguments ica(this->DefaultComponentName); cmCAStringVector files(&ica.Parser, programs ? "PROGRAMS" : "FILES"); - files.Follows(CM_NULLPTR); + files.Follows(nullptr); ica.ArgumentGroup.Follows(&files); std::vector unknownArgs; ica.Parse(&args, &unknownArgs); @@ -816,10 +811,9 @@ bool cmInstallCommand::HandleFilesMode(std::vector const& args) this->Makefile->GetPolicyStatus(cmPolicies::CMP0062); cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator(); - for (std::vector::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; @@ -836,8 +830,8 @@ bool cmInstallCommand::HandleFilesMode(std::vector const& args) messageType = cmake::FATAL_ERROR; } if (modal) { - e << "The file\n " << *fileIt << "\nwas generated by the export() " - "command. It " + 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"; @@ -895,7 +889,7 @@ bool cmInstallCommand::HandleDirectoryMode( bool exclude_from_all = false; bool message_never = false; std::vector dirs; - const char* destination = CM_NULLPTR; + const char* destination = nullptr; std::string permissions_file; std::string permissions_dir; std::vector configurations; @@ -1181,7 +1175,7 @@ bool cmInstallCommand::HandleExportAndroidMKMode( cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES", &ica.ArgumentGroup); cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup); - exp.Follows(CM_NULLPTR); + exp.Follows(nullptr); ica.ArgumentGroup.Follows(&exp); std::vector unknownArgs; @@ -1273,7 +1267,7 @@ bool cmInstallCommand::HandleExportMode(std::vector const& args) cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES", &ica.ArgumentGroup); cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup); - exp.Follows(CM_NULLPTR); + exp.Follows(nullptr); ica.ArgumentGroup.Follows(&exp); std::vector unknownArgs; @@ -1340,10 +1334,7 @@ bool cmInstallCommand::HandleExportMode(std::vector const& args) cmExportSet* exportSet = this->Makefile->GetGlobalGenerator()->GetExportSets()[exp.GetString()]; if (exportOld.IsEnabled()) { - for (std::vector::const_iterator tei = - exportSet->GetTargetExports()->begin(); - tei != exportSet->GetTargetExports()->end(); ++tei) { - cmTargetExport const* te = *tei; + for (cmTargetExport* te : *exportSet->GetTargetExports()) { cmTarget* tgt = this->Makefile->GetGlobalGenerator()->FindTarget(te->TargetName); const bool newCMP0022Behavior = @@ -1380,20 +1371,19 @@ bool cmInstallCommand::MakeFilesFullPath( const char* modeName, const std::vector& relFiles, std::vector& absFiles) { - for (std::vector::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())) { 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; } diff --git a/Source/cmInstallCommand.h b/Source/cmInstallCommand.h index f5d1f9265..8bd015933 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 #include @@ -24,14 +24,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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: bool HandleScriptMode(std::vector const& args); diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx index b73414dd0..12abac81b 100644 --- a/Source/cmInstallCommandArguments.cxx +++ b/Source/cmInstallCommandArguments.cxx @@ -2,15 +2,13 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmInstallCommandArguments.h" -#include "cmConfigure.h" - #include "cmSystemTools.h" // Table of valid permissions. const char* cmInstallCommandArguments::PermissionsTable[] = { "OWNER_READ", "OWNER_WRITE", "OWNER_EXECUTE", "GROUP_READ", "GROUP_WRITE", "GROUP_EXECUTE", "WORLD_READ", "WORLD_WRITE", - "WORLD_EXECUTE", "SETUID", "SETGID", CM_NULLPTR + "WORLD_EXECUTE", "SETUID", "SETGID", nullptr }; const std::string cmInstallCommandArguments::EmptyString; @@ -28,7 +26,7 @@ cmInstallCommandArguments::cmInstallCommandArguments( , Optional(&Parser, "OPTIONAL", &ArgumentGroup) , NamelinkOnly(&Parser, "NAMELINK_ONLY", &ArgumentGroup) , NamelinkSkip(&Parser, "NAMELINK_SKIP", &ArgumentGroup) - , GenericArguments(CM_NULLPTR) + , GenericArguments(nullptr) , DefaultComponentName(defaultComponent) { } @@ -38,10 +36,10 @@ 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 @@ -49,7 +47,7 @@ const std::string& cmInstallCommandArguments::GetComponent() const if (!this->Component.GetString().empty()) { return this->Component.GetString(); } - if (this->GenericArguments != CM_NULLPTR) { + if (this->GenericArguments != nullptr) { return this->GenericArguments->GetComponent(); } if (!this->DefaultComponentName.empty()) { @@ -64,10 +62,10 @@ const std::string& cmInstallCommandArguments::GetRename() const if (!this->Rename.GetString().empty()) { return this->Rename.GetString(); } - 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,10 +73,10 @@ 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 @@ -86,7 +84,7 @@ bool cmInstallCommandArguments::GetOptional() const if (this->Optional.IsEnabled()) { return true; } - if (this->GenericArguments != CM_NULLPTR) { + if (this->GenericArguments != nullptr) { return this->GenericArguments->GetOptional(); } return false; @@ -97,7 +95,7 @@ bool cmInstallCommandArguments::GetExcludeFromAll() const if (this->ExcludeFromAll.IsEnabled()) { return true; } - if (this->GenericArguments != CM_NULLPTR) { + if (this->GenericArguments != nullptr) { return this->GenericArguments->GetExcludeFromAll(); } return false; @@ -108,7 +106,7 @@ bool cmInstallCommandArguments::GetNamelinkOnly() const if (this->NamelinkOnly.IsEnabled()) { return true; } - if (this->GenericArguments != CM_NULLPTR) { + if (this->GenericArguments != nullptr) { return this->GenericArguments->GetNamelinkOnly(); } return false; @@ -119,7 +117,7 @@ bool cmInstallCommandArguments::GetNamelinkSkip() const if (this->NamelinkSkip.IsEnabled()) { return true; } - if (this->GenericArguments != CM_NULLPTR) { + if (this->GenericArguments != nullptr) { return this->GenericArguments->GetNamelinkSkip(); } return false; @@ -131,7 +129,7 @@ const std::vector& cmInstallCommandArguments::GetConfigurations() if (!this->Configurations.GetVector().empty()) { return this->Configurations.GetVector(); } - if (this->GenericArguments != CM_NULLPTR) { + if (this->GenericArguments != nullptr) { return this->GenericArguments->GetConfigurations(); } return this->Configurations.GetVector(); @@ -155,11 +153,9 @@ void cmInstallCommandArguments::Parse(const std::vector* args, bool cmInstallCommandArguments::CheckPermissions() { - this->PermissionsString = ""; - for (std::vector::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.GetVector()) { + if (!this->CheckPermissions(perm, this->PermissionsString)) { return false; } } diff --git a/Source/cmInstallDirectoryGenerator.cxx b/Source/cmInstallDirectoryGenerator.cxx index 54ad85c3b..e4209bd22 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 // IWYU pragma: keep cmInstallDirectoryGenerator::cmInstallDirectoryGenerator( std::vector 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) @@ -62,19 +63,17 @@ void cmInstallDirectoryGenerator::GenerateScriptForConfig( { std::vector dirs; cmGeneratorExpression ge; - for (std::vector::const_iterator i = this->Directories.begin(); - i != this->Directories.end(); ++i) { - CM_AUTO_PTR cge = ge.Parse(*i); + for (std::string const& d : this->Directories) { + std::unique_ptr 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::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.c_str())) { + d = std::string(mf.GetCurrentSourceDirectory()) + "/" + d; } } @@ -86,7 +85,7 @@ void cmInstallDirectoryGenerator::AddDirectoryInstallRule( std::vector 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..ac6e50457 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 #include @@ -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; + void 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 const& dirs); diff --git a/Source/cmInstallExportAndroidMKGenerator.cxx b/Source/cmInstallExportAndroidMKGenerator.cxx index 8eeaa9c7c..dd85b8843 100644 --- a/Source/cmInstallExportAndroidMKGenerator.cxx +++ b/Source/cmInstallExportAndroidMKGenerator.cxx @@ -95,8 +95,8 @@ void cmInstallExportAndroidMKGenerator::GenerateScriptConfigs( 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(); } @@ -135,6 +135,6 @@ void cmInstallExportAndroidMKGenerator::GenerateScriptActions( std::vector 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.cxx b/Source/cmInstallExportGenerator.cxx index b176e85c5..fdd231ca7 100644 --- a/Source/cmInstallExportGenerator.cxx +++ b/Source/cmInstallExportGenerator.cxx @@ -3,7 +3,6 @@ #include "cmInstallExportGenerator.h" #include -#include #include #include @@ -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 @@ -111,11 +110,9 @@ size_t cmInstallExportGenerator::GetMaxConfigLength() const len = this->ConfigurationName.size(); } } else { - for (std::vector::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(); } } } @@ -153,10 +150,8 @@ void cmInstallExportGenerator::GenerateScript(std::ostream& os) this->EFGen->AddConfiguration(""); } } else { - for (std::vector::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 +169,13 @@ void cmInstallExportGenerator::GenerateScriptConfigs(std::ostream& os, // Now create a configuration-specific install rule for the import // file of each configuration. std::vector files; - for (std::map::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(); } @@ -221,6 +214,6 @@ void cmInstallExportGenerator::GenerateScriptActions(std::ostream& os, std::vector 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..d23cf063d 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; + void 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.h b/Source/cmInstallFilesCommand.h index b3c27b827..19f255902 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 #include @@ -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 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; diff --git a/Source/cmInstallFilesGenerator.cxx b/Source/cmInstallFilesGenerator.cxx index 6323a9189..68e3f86d1 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 // 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) @@ -58,12 +59,12 @@ void cmInstallFilesGenerator::AddFilesInstallRule( std::vector 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 +82,8 @@ void cmInstallFilesGenerator::GenerateScriptForConfig( { std::vector files; cmGeneratorExpression ge; - for (std::vector::const_iterator i = this->Files.begin(); - i != this->Files.end(); ++i) { - CM_AUTO_PTR cge = ge.Parse(*i); + for (std::string const& f : this->Files) { + std::unique_ptr cge = ge.Parse(f); cmSystemTools::ExpandListArgument( cge->Evaluate(this->LocalGenerator, config), files); } diff --git a/Source/cmInstallFilesGenerator.h b/Source/cmInstallFilesGenerator.h index 62b57f9c7..0ef2a06b0 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; + void 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 const& files); diff --git a/Source/cmInstallGenerator.cxx b/Source/cmInstallGenerator.cxx index 13b588efb..4d019782b 100644 --- a/Source/cmInstallGenerator.cxx +++ b/Source/cmInstallGenerator.cxx @@ -113,9 +113,8 @@ void cmInstallGenerator::AddInstallRule( if (files.size() == 1) { os << " \"" << files[0] << "\""; } else { - for (std::vector::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 +130,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 = "\"x${CMAKE_INSTALL_COMPONENT}x\" STREQUAL \"x"; result += component; - result += "\""; + result += "x\""; if (!exclude_from_all) { result += " OR NOT CMAKE_INSTALL_COMPONENT"; } diff --git a/Source/cmInstallGenerator.h b/Source/cmInstallGenerator.h index 8f8701f1a..fc1ce864f 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" @@ -36,14 +36,14 @@ public: std::vector const& configurations, const char* component, MessageLevel message, bool exclude_from_all); - ~cmInstallGenerator() CM_OVERRIDE; + ~cmInstallGenerator() override; void AddInstallRule( std::ostream& os, std::string const& dest, cmInstallType type, std::vector 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. */ @@ -58,7 +58,7 @@ public: virtual void Compute(cmLocalGenerator*) {} 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.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 #include @@ -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 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..f7e6e44a3 100644 --- a/Source/cmInstallScriptGenerator.cxx +++ b/Source/cmInstallScriptGenerator.cxx @@ -11,7 +11,7 @@ cmInstallScriptGenerator::cmInstallScriptGenerator(const char* script, bool code, const char* component, bool exclude_from_all) - : cmInstallGenerator(CM_NULLPTR, std::vector(), component, + : cmInstallGenerator(nullptr, std::vector(), component, MessageDefault, exclude_from_all) , Script(script) , Code(code) diff --git a/Source/cmInstallScriptGenerator.h b/Source/cmInstallScriptGenerator.h index e183999d0..fe0f7c6f1 100644 --- a/Source/cmInstallScriptGenerator.h +++ b/Source/cmInstallScriptGenerator.h @@ -3,7 +3,7 @@ #ifndef cmInstallScriptGenerator_h #define cmInstallScriptGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmInstallGenerator.h" @@ -18,10 +18,10 @@ class cmInstallScriptGenerator : public cmInstallGenerator public: cmInstallScriptGenerator(const char* script, bool code, const char* component, bool exclude_from_all); - ~cmInstallScriptGenerator() CM_OVERRIDE; + ~cmInstallScriptGenerator() override; protected: - void GenerateScript(std::ostream& os) CM_OVERRIDE; + void GenerateScript(std::ostream& os) override; std::string Script; bool Code; }; diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index 84d6f7ac9..b964794ed 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -28,7 +28,7 @@ cmInstallTargetGenerator::cmInstallTargetGenerator( : cmInstallGenerator(dest, configurations, component, message, exclude_from_all) , TargetName(targetName) - , Target(CM_NULLPTR) + , Target(nullptr) , FilePermissions(file_permissions) , ImportLibrary(implib) , Optional(optional) @@ -312,8 +312,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 +351,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 +362,8 @@ void cmInstallTargetGenerator::GetInstallObjectNames( std::string const& config, std::vector& objects) const { this->Target->GetTargetObjectNames(config, objects); - for (std::vector::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; } } @@ -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::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 const& sharedLibs = cli->GetSharedLibrariesLinked(); - for (std::set::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::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"; } @@ -702,10 +693,9 @@ void cmInstallTargetGenerator::AddChrpathPatchRule( // Note: These paths are kept unique to avoid // install_name_tool corruption. std::set runpaths; - for (std::vector::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::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 diff --git a/Source/cmInstallTargetGenerator.h b/Source/cmInstallTargetGenerator.h index cf2de58f9..f6bec20b3 100644 --- a/Source/cmInstallTargetGenerator.h +++ b/Source/cmInstallTargetGenerator.h @@ -3,7 +3,7 @@ #ifndef cmInstallTargetGenerator_h #define cmInstallTargetGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmInstallGenerator.h" #include "cmScriptGenerator.h" @@ -26,7 +26,7 @@ public: std::vector const& configurations, const char* component, MessageLevel message, bool exclude_from_all, bool optional); - ~cmInstallTargetGenerator() CM_OVERRIDE; + ~cmInstallTargetGenerator() override; /** Select the policy for installing shared library linkable name symlinks. */ @@ -56,7 +56,7 @@ public: const std::string& config, NameType nameType = NameNormal); - void Compute(cmLocalGenerator* lg) CM_OVERRIDE; + void Compute(cmLocalGenerator* lg) override; cmGeneratorTarget* GetTarget() const { return this->Target; } @@ -65,9 +65,9 @@ public: std::string GetDestination(std::string const& config) const; protected: - void GenerateScript(std::ostream& os) CM_OVERRIDE; + void GenerateScript(std::ostream& os) 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); diff --git a/Source/cmInstallTargetsCommand.cxx b/Source/cmInstallTargetsCommand.cxx index e00eba012..d721ca0ee 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 #include #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmTarget.h" -#include "cm_unordered_map.hxx" class cmExecutionStatus; 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmInstalledFile.cxx b/Source/cmInstalledFile.cxx index d51fd8d74..3ffeabdb5 100644 --- a/Source/cmInstalledFile.cxx +++ b/Source/cmInstalledFile.cxx @@ -7,19 +7,16 @@ #include "cmMakefile.h" #include "cmSystemTools.h" -#include "cmConfigure.h" #include cmInstalledFile::cmInstalledFile() - : NameExpression(CM_NULLPTR) + : NameExpression(nullptr) { } cmInstalledFile::~cmInstalledFile() { - if (NameExpression) { - delete NameExpression; - } + delete NameExpression; } cmInstalledFile::Property::Property() @@ -91,11 +88,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 = ";"; } diff --git a/Source/cmInstalledFile.h b/Source/cmInstalledFile.h index fbf754ffd..47a49590d 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 +#include // IWYU pragma: keep #include #include @@ -22,7 +22,7 @@ class cmMakefile; class cmInstalledFile { public: - typedef CM_AUTO_PTR + typedef std::unique_ptr CompiledGeneratorExpressionPtrType; typedef std::vector ExpressionVectorType; diff --git a/Source/cmLinkDirectoriesCommand.cxx b/Source/cmLinkDirectoriesCommand.cxx index 9b0c28817..98ab7e7b3 100644 --- a/Source/cmLinkDirectoriesCommand.cxx +++ b/Source/cmLinkDirectoriesCommand.cxx @@ -19,9 +19,8 @@ bool cmLinkDirectoriesCommand::InitialPass( return true; } - for (std::vector::const_iterator i = args.begin(); - i != args.end(); ++i) { - this->AddLinkDir(*i); + for (std::string const& i : args) { + this->AddLinkDir(i); } return true; } diff --git a/Source/cmLinkDirectoriesCommand.h b/Source/cmLinkDirectoriesCommand.h index b64e48d70..3fd4e50ab 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 #include @@ -26,14 +26,14 @@ 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: void AddLinkDir(std::string const& dir); diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h index f0fded21f..e8c94871b 100644 --- a/Source/cmLinkItem.h +++ b/Source/cmLinkItem.h @@ -3,7 +3,7 @@ #ifndef cmLinkItem_h #define cmLinkItem_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -24,7 +24,7 @@ class cmLinkItem : public std::string public: cmLinkItem() : std_string() - , Target(CM_NULLPTR) + , Target(nullptr) { } cmLinkItem(const std_string& n, cmGeneratorTarget const* t) @@ -105,7 +105,7 @@ struct cmOptionalLinkInterface : public cmLinkInterface , AllDone(false) , Exists(false) , HadHeadSensitiveCondition(false) - , ExplicitLibraries(CM_NULLPTR) + , ExplicitLibraries(nullptr) { } bool LibrariesDone; 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmLinkLineComputer.cxx b/Source/cmLinkLineComputer.cxx index c0f702e25..7511fd21b 100644 --- a/Source/cmLinkLineComputer.cxx +++ b/Source/cmLinkLineComputer.cxx @@ -59,17 +59,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 += " "; } @@ -103,9 +102,8 @@ std::string cmLinkLineComputer::ComputeLinkPath( { std::string linkPath; std::vector const& libDirs = cli.GetDirectories(); - for (std::vector::const_iterator libDir = libDirs.begin(); - libDir != libDirs.end(); ++libDir) { - std::string libpath = this->ConvertToOutputForExisting(*libDir); + for (std::string const& libDir : libDirs) { + std::string libpath = this->ConvertToOutputForExisting(libDir); linkPath += " " + libPathFlag; linkPath += libpath; linkPath += libPathTerminator; @@ -123,10 +121,9 @@ std::string cmLinkLineComputer::ComputeRPath(cmComputeLinkInformation& cli) std::vector runtimeDirs; cli.GetRPath(runtimeDirs, this->Relink); - for (std::vector::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 +147,9 @@ std::string cmLinkLineComputer::ComputeFrameworkPath( std::string frameworkPath; if (!fwSearchFlag.empty()) { std::vector const& fwDirs = cli.GetFrameworkPaths(); - for (std::vector::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..a016358fa 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 diff --git a/Source/cmLinkLineDeviceComputer.cxx b/Source/cmLinkLineDeviceComputer.cxx index 942e9b92c..3beeae321 100644 --- a/Source/cmLinkLineDeviceComputer.cxx +++ b/Source/cmLinkLineDeviceComputer.cxx @@ -5,7 +5,6 @@ #include #include -#include #include "cmComputeLinkInformation.h" #include "cmGeneratorTarget.h" @@ -32,14 +31,13 @@ std::string cmLinkLineDeviceComputer::ComputeLinkLibraries( 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) { + for (auto const& item : items) { + if (!item.Target) { continue; } bool skippable = false; - switch (li->Target->GetType()) { + switch (item.Target->GetType()) { case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::MODULE_LIBRARY: case cmStateEnums::INTERFACE_LIBRARY: @@ -49,7 +47,7 @@ std::string cmLinkLineDeviceComputer::ComputeLinkLibraries( // 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"); + item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS"); break; default: break; @@ -60,16 +58,16 @@ std::string cmLinkLineDeviceComputer::ComputeLinkLibraries( } std::set langs; - li->Target->GetLanguages(langs, config); + item.Target->GetLanguages(langs, config); if (langs.count("CUDA") == 0) { continue; } - if (li->IsPath) { + if (item.IsPath) { fout << this->ConvertToOutputFormat( - this->ConvertToLinkReference(li->Value)); + this->ConvertToLinkReference(item.Value)); } else { - fout << li->Value; + fout << item.Value; } fout << " "; } diff --git a/Source/cmLinkLineDeviceComputer.h b/Source/cmLinkLineDeviceComputer.h index c3fac6182..81b48b3d4 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 @@ -23,14 +23,13 @@ class cmLinkLineDeviceComputer : public cmLinkLineComputer public: cmLinkLineDeviceComputer(cmOutputConverter* outputConverter, cmStateDirectory const& stateDir); - ~cmLinkLineDeviceComputer() CM_OVERRIDE; + ~cmLinkLineDeviceComputer() override; 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 @@ -42,8 +41,7 @@ public: cmStateDirectory const& stateDir, cmGlobalNinjaGenerator const* gg); - std::string ConvertToLinkReference(std::string const& input) const - CM_OVERRIDE; + std::string ConvertToLinkReference(std::string const& input) const override; private: cmGlobalNinjaGenerator const* GG; diff --git a/Source/cmLinkedTree.h b/Source/cmLinkedTree.h index 55592cb35..8865e23a1 100644 --- a/Source/cmLinkedTree.h +++ b/Source/cmLinkedTree.h @@ -3,7 +3,7 @@ #ifndef cmLinkedTree_h #define cmLinkedTree_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -49,7 +49,7 @@ public: public: iterator() - : Tree(CM_NULLPTR) + : Tree(nullptr) , Position(0) { } diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 0542c4fce..ae4f0a84e 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -182,9 +182,9 @@ bool cmListCommand::HandleGetCommand(std::vector const& args) value += sep; sep = ";"; if (item < 0) { - item = (int)nitem + item; + item = static_cast(nitem) + item; } - if (item < 0 || nitem <= (size_t)item) { + if (item < 0 || nitem <= static_cast(item)) { std::ostringstream str; str << "index: " << item << " out of range (-" << nitem << ", " << nitem - 1 << ")"; @@ -273,9 +273,9 @@ bool cmListCommand::HandleInsertCommand(std::vector const& args) if (!varArgsExpanded.empty()) { size_t nitem = varArgsExpanded.size(); if (item < 0) { - item = (int)nitem + item; + item = static_cast(nitem) + item; } - if (item < 0 || nitem <= (size_t)item) { + if (item < 0 || nitem <= static_cast(item)) { std::ostringstream str; str << "index: " << item << " out of range (-" << varArgsExpanded.size() << ", " @@ -423,9 +423,9 @@ bool cmListCommand::HandleRemoveAtCommand(std::vector 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(nitem) + item; } - if (item < 0 || nitem <= (size_t)item) { + if (item < 0 || nitem <= static_cast(item)) { std::ostringstream str; str << "index: " << item << " out of range (-" << nitem << ", " << nitem - 1 << ")"; diff --git a/Source/cmListCommand.h b/Source/cmListCommand.h index 7789f7df1..29653998c 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 #include @@ -22,14 +22,14 @@ 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; protected: bool HandleLengthCommand(std::vector const& args); diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 0c73cd725..8e8a54d5f 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -9,7 +9,6 @@ #include "cmSystemTools.h" #include "cmake.h" -#include "cmConfigure.h" #include #include #include @@ -82,7 +81,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 +89,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; @@ -330,13 +329,13 @@ cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& bottom, cmListFileBacktrace::cmListFileBacktrace() : Bottom() - , Cur(CM_NULLPTR) + , Cur(nullptr) { } cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& snapshot) : Bottom(snapshot.GetCallStackBottom()) - , Cur(CM_NULLPTR) + , Cur(nullptr) { } diff --git a/Source/cmLoadCacheCommand.cxx b/Source/cmLoadCacheCommand.cxx index 00a30bf0e..32fdef51c 100644 --- a/Source/cmLoadCacheCommand.cxx +++ b/Source/cmLoadCacheCommand.cxx @@ -27,17 +27,16 @@ bool cmLoadCacheCommand::InitialPass(std::vector 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 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 const& args, bool includeFiles = false; std::set 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); } @@ -125,7 +124,7 @@ bool cmLoadCacheCommand::ReadWithPrefix(std::vector 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; protected: std::set VariablesToRead; diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx index 92a32a147..6bfac172f 100644 --- a/Source/cmLoadCommandCommand.cxx +++ b/Source/cmLoadCommandCommand.cxx @@ -34,12 +34,12 @@ public: } ///! clean up any memory allocated by the plugin - ~cmLoadedCommand() CM_OVERRIDE; + ~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 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 const& args, cmExecutionStatus&) @@ -118,17 +118,16 @@ bool cmLoadedCommand::InitialPass(std::vector const& args, // create argc and argv and then invoke the command int argc = static_cast(args.size()); - char** argv = CM_NULLPTR; + char** argv = nullptr; if (argc) { - argv = (char**)malloc(argc * sizeof(char*)); + argv = static_cast(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 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 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( + cmsys::DynamicLoader::GetSymbolAddress(lib, initFuncName)); if (!initFunction) { initFuncName = "_"; initFuncName += args[0]; initFuncName += "Init"; - initFunction = (CM_INIT_FUNCTION)( + initFunction = reinterpret_cast( 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx index 6524db401..50ebfa119 100644 --- a/Source/cmLocalCommonGenerator.cxx +++ b/Source/cmLocalCommonGenerator.cxx @@ -22,7 +22,7 @@ cmLocalCommonGenerator::cmLocalCommonGenerator(cmGlobalGenerator* gg, this->ConfigName = config; } else { // No configuration type given. - this->ConfigName = ""; + this->ConfigName.clear(); } } @@ -67,10 +67,9 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags( this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG")) { std::vector includes; this->GetIncludeDirectories(includes, target, "C", config); - for (std::vector::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); } } diff --git a/Source/cmLocalCommonGenerator.h b/Source/cmLocalCommonGenerator.h index a5afcd87d..a60573ca6 100644 --- a/Source/cmLocalCommonGenerator.h +++ b/Source/cmLocalCommonGenerator.h @@ -3,7 +3,7 @@ #ifndef cmLocalCommonGenerator_h #define cmLocalCommonGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include @@ -21,14 +21,14 @@ class cmLocalCommonGenerator : public cmLocalGenerator public: cmLocalCommonGenerator(cmGlobalGenerator* gg, cmMakefile* mf, std::string const& wd); - ~cmLocalCommonGenerator() CM_OVERRIDE; + ~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; protected: std::string WorkingDirectory; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 6ce31c5ea..1a088ea9e 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -102,9 +102,7 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile) this->LinkerSysroot = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT"); } - for (std::vector::iterator i = enabledLanguages.begin(); - i != enabledLanguages.end(); ++i) { - std::string const& lang = *i; + for (std::string const& lang : enabledLanguages) { if (lang == "NONE") { continue; } @@ -209,18 +207,16 @@ void cmLocalGenerator::TraceDependencies() if (configs.empty()) { configs.push_back(""); } - for (std::vector::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 targets = this->GetGeneratorTargets(); - for (std::vector::iterator t = targets.begin(); - t != targets.end(); ++t) { - if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + const std::vector& targets = this->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { + if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } - (*t)->TraceDependencies(); + target->TraceDependencies(); } } @@ -259,34 +255,60 @@ void cmLocalGenerator::GenerateTestFiles() fout << "include(\"" << testIncludeFile << "\")" << std::endl; } + const char* testIncludeFiles = + this->Makefile->GetProperty("TEST_INCLUDE_FILES"); + if (testIncludeFiles) { + std::vector 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 const& testers = this->Makefile->GetTestGenerators(); - for (std::vector::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 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(); + std::string outP = i.GetDirectory().GetCurrentBinary(); outP = this->ConvertToRelativePath(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 ef = this->Makefile->GetEvaluationFiles(); - for (std::vector::const_iterator li = - ef.begin(); - li != ef.end(); ++li) { - (*li)->CreateOutputFile(this, config); + for (cmGeneratorExpressionEvaluationFile* geef : ef) { + geef->CreateOutputFile(this, config); } } @@ -295,14 +317,12 @@ void cmLocalGenerator::ProcessEvaluationFiles( { std::vector ef = this->Makefile->GetEvaluationFiles(); - for (std::vector::const_iterator li = - ef.begin(); - li != ef.end(); ++li) { - (*li)->Generate(this); + for (cmGeneratorExpressionEvaluationFile* geef : ef) { + geef->Generate(this); if (cmSystemTools::GetFatalErrorOccured()) { return; } - std::vector files = (*li)->GetFiles(); + std::vector files = geef->GetFiles(); std::sort(files.begin(), files.end()); std::vector intersection; @@ -327,6 +347,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 +391,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::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; } } } @@ -451,13 +471,24 @@ 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 */ + } + // Ask each install generator to write its code. std::vector const& installers = this->Makefile->GetInstallGenerators(); - for (std::vector::const_iterator gi = - installers.begin(); - gi != installers.end(); ++gi) { - (*gi)->Generate(fout, config, configurationTypes); + for (cmInstallGenerator* installer : installers) { + installer->Generate(fout, config, configurationTypes); } // Write rules from old-style specification stored in targets. @@ -469,10 +500,9 @@ void cmLocalGenerator::GenerateInstallRules() if (!children.empty()) { fout << "if(NOT CMAKE_INSTALL_LOCAL_ONLY)\n"; fout << " # Include the install script for each subdirectory.\n"; - for (std::vector::const_iterator ci = children.begin(); - ci != children.end(); ++ci) { - if (!ci->GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL")) { - std::string odir = ci->GetDirectory().GetCurrentBinary(); + 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; @@ -504,6 +534,8 @@ void cmLocalGenerator::GenerateInstallRules() void cmLocalGenerator::AddGeneratorTarget(cmGeneratorTarget* gt) { this->GeneratorTargets.push_back(gt); + this->GeneratorTargetSearchIndex.insert( + std::pair(gt->GetName(), gt)); this->GlobalGenerator->IndexGeneratorTarget(gt); } @@ -537,13 +569,12 @@ private: cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget( const std::string& name) const { - std::vector::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() @@ -556,17 +587,13 @@ void cmLocalGenerator::ComputeTargetManifest() } // Add our targets to the manifest for each configuration. - std::vector targets = this->GetGeneratorTargets(); - for (std::vector::iterator t = targets.begin(); - t != targets.end(); ++t) { - cmGeneratorTarget* target = *t; + const std::vector& targets = this->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } - for (std::vector::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); } } } @@ -581,13 +608,10 @@ bool cmLocalGenerator::ComputeTargetCompileFeatures() } // Process compile features of all targets. - std::vector targets = this->GetGeneratorTargets(); - for (std::vector::iterator t = targets.begin(); - t != targets.end(); ++t) { - cmGeneratorTarget* target = *t; - for (std::vector::iterator ci = configNames.begin(); - ci != configNames.end(); ++ci) { - if (!target->ComputeCompileFeatures(*ci)) { + const std::vector& targets = this->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { + for (std::string const& c : configNames) { + if (!target->ComputeCompileFeatures(c)) { return false; } } @@ -663,7 +687,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 +708,15 @@ std::string cmLocalGenerator::GetIncludeFlags( #ifdef __APPLE__ emitted.insert("/System/Library/Frameworks"); #endif - std::vector::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.c_str())) { + 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)) { includeFlags << sysFwSearchFlag; } else { includeFlags << fwSearchFlag; @@ -706,7 +729,7 @@ std::string cmLocalGenerator::GetIncludeFlags( if (!flagUsed || repeatFlag) { if (sysIncludeFlag && target && - target->IsSystemIncludeDirectory(*i, config)) { + target->IsSystemIncludeDirectory(i, config)) { includeFlags << sysIncludeFlag; } else { includeFlags << includeFlag; @@ -714,7 +737,7 @@ std::string cmLocalGenerator::GetIncludeFlags( flagUsed = true; } std::string includePath = - this->ConvertToIncludeReference(*i, shellFormat, forceFullPaths); + this->ConvertToIncludeReference(i, shellFormat, forceFullPaths); if (quotePaths && !includePath.empty() && includePath[0] != '\"') { includeFlags << "\""; } @@ -758,12 +781,11 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, cmSystemTools::ParseWindowsCommandLine(targetFlags, opts); } target->GetCompileOptions(opts, config, lang); - for (std::vector::const_iterator i = opts.begin(); - i != opts.end(); ++i) { - if (r.find(i->c_str())) { + for (std::string const& opt : opts) { + if (r.find(opt.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); + this->AppendFlagEscape(flags, opt); } } } else { @@ -774,30 +796,27 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags, } std::vector opts; target->GetCompileOptions(opts, config, lang); - for (std::vector::const_iterator i = opts.begin(); - i != opts.end(); ++i) { + for (std::string const& opt : opts) { // COMPILE_OPTIONS are escaped. - this->AppendFlagEscape(flags, *i); + this->AppendFlagEscape(flags, opt); } } - for (std::map::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 " @@ -872,13 +891,12 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, if (const char* value = this->Makefile->GetDefinition(impDirVar)) { std::vector impDirVec; cmSystemTools::ExpandListArgument(value, impDirVec); - for (std::vector::const_iterator i = impDirVec.begin(); - i != impDirVec.end(); ++i) { - std::string d = rootPath + *i; + for (std::string const& i : impDirVec) { + std::string d = rootPath + i; cmSystemTools::ConvertToUnixSlashes(d); emitted.insert(d); if (!stripImplicitInclDirs) { - implicitDirs.push_back(*i); + implicitDirs.push_back(i); } } } @@ -893,26 +911,24 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, if (this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE")) { const char* topSourceDir = this->GetState()->GetSourceDirectory(); const char* topBinaryDir = this->GetState()->GetBinaryDirectory(); - for (std::vector::const_iterator i = includes.begin(); - i != includes.end(); ++i) { + for (std::string const& i : includes) { // 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(i, topSourceDir) || + cmSystemTools::ComparePath(i, topBinaryDir) || + cmSystemTools::IsSubDirectory(i, topSourceDir) || + cmSystemTools::IsSubDirectory(i, topBinaryDir)) { + if (emitted.insert(i).second) { + dirs.push_back(i); } } } } // Construct the final ordered include directory list. - for (std::vector::const_iterator i = includes.begin(); - i != includes.end(); ++i) { - if (emitted.insert(*i).second) { - dirs.push_back(*i); + for (std::string const& i : includes) { + if (emitted.insert(i).second) { + dirs.push_back(i); } } @@ -930,10 +946,9 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, dirs.push_back(*i); } - for (std::vector::const_iterator i = implicitDirs.begin(); - i != implicitDirs.end(); ++i) { - if (std::find(includes.begin(), includes.end(), *i) != includes.end()) { - dirs.push_back(*i); + for (std::string const& i : implicitDirs) { + if (std::find(includes.begin(), includes.end(), i) != includes.end()) { + dirs.push_back(i); } } } @@ -991,9 +1006,7 @@ void cmLocalGenerator::GetTargetFlags( target->GetSourceFiles(sources, buildType); std::string defFlag = this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG"); - for (std::vector::const_iterator i = sources.begin(); - i != sources.end(); ++i) { - cmSourceFile* sf = *i; + for (cmSourceFile* sf : sources) { if (sf->GetExtension() == "def") { linkFlags += defFlag; linkFlags += this->ConvertToOutputFormat( @@ -1144,10 +1157,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::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 +1169,11 @@ static std::string GetFrameworkFlags(const std::string& lang, std::string flags; if (cmComputeLinkInformation* cli = target->GetLinkInformation(config)) { std::vector const& frameworks = cli->GetFrameworkPaths(); - for (std::vector::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 += " "; } } @@ -1301,7 +1313,7 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags, 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 +1326,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::iterator i = archs.begin(); - i != archs.end(); ++i) { + for (std::string const& arch : archs) { flags += " -arch "; - flags += *i; + flags += arch; } } @@ -1399,7 +1410,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; } @@ -1502,20 +1513,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 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 = @@ -1535,14 +1560,14 @@ void cmLocalGenerator::AddCompilerRequirementFlag( } else { std::vector 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 > langStdMap; + static std::map> langStdMap; if (langStdMap.empty()) { // Maintain sorted order, most recent first. langStdMap["CXX"].push_back("17"); @@ -1583,8 +1608,10 @@ void cmLocalGenerator::AddCompilerRequirementFlag( 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"; @@ -1593,12 +1620,15 @@ void cmLocalGenerator::AddCompilerRequirementFlag( target->Target->GetMakefile()->GetRequiredDefinition(option_flag); std::vector 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 +1637,8 @@ void cmLocalGenerator::AddCompilerRequirementFlag( target->Target->GetMakefile()->GetDefinition(option_flag)) { std::vector 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; } @@ -1679,7 +1709,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()) { @@ -1790,7 +1820,7 @@ void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags, std::string const& lang, int targetType) { - const char* picFlags = CM_NULLPTR; + const char* picFlags = nullptr; if (targetType == cmStateEnums::EXECUTABLE) { std::string flagsVar = "CMAKE_"; @@ -1807,9 +1837,8 @@ void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags, if (picFlags) { std::vector options; cmSystemTools::ExpandListArgument(picFlags, options); - for (std::vector::const_iterator oi = options.begin(); - oi != options.end(); ++oi) { - this->AppendFlagEscape(flags, *oi); + for (std::string const& o : options) { + this->AppendFlagEscape(flags, o); } } } @@ -1873,15 +1902,14 @@ 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 flagsList; cmSystemTools::ExpandListArgument(rawFlagsList, flagsList); - for (std::vector::const_iterator oi = flagsList.begin(); - oi != flagsList.end(); ++oi) { - this->AppendFlagEscape(flags, *oi); + for (std::string const& o : flagsList) { + this->AppendFlagEscape(flags, o); } } @@ -1903,13 +1931,12 @@ void cmLocalGenerator::AppendDefines( std::set& defines, const std::vector& defines_vec) const { - for (std::vector::const_iterator di = defines_vec.begin(); - di != defines_vec.end(); ++di) { + for (std::string const& d : defines_vec) { // Skip unsupported definitions. - if (!this->CheckDefinition(*di)) { + if (!this->CheckDefinition(d)) { continue; } - defines.insert(*di); + defines.insert(d); } } @@ -1979,9 +2006,8 @@ void cmLocalGenerator::AppendFeatureOptions(std::string& flags, if (const char* optionList = this->Makefile->GetDefinition(optVar)) { std::vector options; cmSystemTools::ExpandListArgument(optionList, options); - for (std::vector::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 +2029,7 @@ const char* cmLocalGenerator::GetFeature(const std::string& feature, } snp = snp.GetBuildsystemDirectoryParent(); } - return CM_NULLPTR; + return nullptr; } std::string cmLocalGenerator::GetProjectName() const @@ -2025,10 +2051,9 @@ std::string cmLocalGenerator::ConstructComment( comment = "Generating "; const char* sep = ""; std::string currentBinaryDir = this->GetCurrentBinaryDirectory(); - for (std::vector::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->ConvertToRelativePath(currentBinaryDir, o); sep = ", "; } return comment; @@ -2058,37 +2083,36 @@ void cmLocalGenerator::GenerateTargetInstallRules( { // Convert the old-style install specification from each target to // an install generator and run it. - std::vector tgts = this->GetGeneratorTargets(); - for (std::vector::iterator l = tgts.begin(); - l != tgts.end(); ++l) { - if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + const std::vector& 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 +2121,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 +2143,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); } } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 9f78be465..4a7d2ca64 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -3,13 +3,14 @@ #ifndef cmLocalGenerator_h #define cmLocalGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cm_kwiml.h" #include #include #include #include +#include #include #include "cmListFileCache.h" @@ -282,8 +283,8 @@ public: // 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, @@ -311,7 +312,7 @@ public: virtual void ComputeObjectFilenames( std::map& mapping, - cmGeneratorTarget const* gt = CM_NULLPTR); + cmGeneratorTarget const* gt = nullptr); bool IsWindowsShell() const; bool IsWatcomWMake() const; @@ -353,8 +354,12 @@ protected: std::string::size_type ObjectPathMax; std::set ObjectMaxPathViolations; - std::set WarnCMP0063; + typedef std::unordered_map + GeneratorTargetMap; + GeneratorTargetMap GeneratorTargetSearchIndex; std::vector GeneratorTargets; + + std::set WarnCMP0063; std::vector ImportedGeneratorTargets; std::vector OwnedImportedGeneratorTargets; std::map AliasTargets; diff --git a/Source/cmLocalGhsMultiGenerator.cxx b/Source/cmLocalGhsMultiGenerator.cxx index 5f37af528..ab6774e00 100644 --- a/Source/cmLocalGhsMultiGenerator.cxx +++ b/Source/cmLocalGhsMultiGenerator.cxx @@ -20,9 +20,9 @@ cmLocalGhsMultiGenerator::~cmLocalGhsMultiGenerator() void cmLocalGhsMultiGenerator::Generate() { - std::vector tgts = this->GetGeneratorTargets(); + const std::vector& tgts = this->GetGeneratorTargets(); - for (std::vector::iterator l = tgts.begin(); + for (std::vector::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 266710cb1..477ce51f0 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -5,6 +5,7 @@ #include #include #include +#include // IWYU pragma: keep #include #include #include @@ -22,7 +23,6 @@ #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg, @@ -55,7 +55,7 @@ void cmLocalNinjaGenerator::Generate() this->HomeRelativeOutputPath = this->ConvertToRelativePath( this->GetBinaryDirectory(), this->GetCurrentBinaryDirectory()); if (this->HomeRelativeOutputPath == ".") { - this->HomeRelativeOutputPath = ""; + this->HomeRelativeOutputPath.clear(); } this->WriteProcessedMakefile(this->GetBuildFileStream()); @@ -79,19 +79,19 @@ void cmLocalNinjaGenerator::Generate() } } - std::vector targets = this->GetGeneratorTargets(); - for (std::vector::iterator t = targets.begin(); - t != targets.end(); ++t) { - if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + const std::vector& targets = this->GetGeneratorTargets(); + for (cmGeneratorTarget* target : targets) { + if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } - cmNinjaTargetGenerator* tg = cmNinjaTargetGenerator::New(*t); + cmNinjaTargetGenerator* 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; } @@ -212,8 +212,7 @@ void cmLocalNinjaGenerator::WritePools(std::ostream& os) os, "Pools defined by global property JOB_POOLS"); std::vector 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 && @@ -250,12 +249,10 @@ void cmLocalNinjaGenerator::ComputeObjectFilenames( { // Determine if these object files should use a custom extension char const* custom_ext = gt->GetCustomObjectExtension(); - for (std::map::iterator si = - mapping.begin(); - si != mapping.end(); ++si) { - cmSourceFile const* sf = si->first; + for (auto& si : mapping) { + cmSourceFile const* sf = si.first; bool keptSourceExtension; - si->second = this->GetObjectFileNameWithoutTarget( + si.second = this->GetObjectFileNameWithoutTarget( *sf, gt->ObjectDirectory, &keptSourceExtension, custom_ext); } } @@ -291,10 +288,9 @@ void cmLocalNinjaGenerator::AppendCustomCommandDeps( cmCustomCommandGenerator const& ccg, cmNinjaDeps& ninjaDeps) { const std::vector& deps = ccg.GetDepends(); - for (std::vector::const_iterator i = deps.begin(); - i != deps.end(); ++i) { + for (std::string const& i : deps) { std::string dep; - if (this->GetRealDependency(*i, this->GetConfigName(), dep)) { + if (this->GetRealDependency(i, this->GetConfigName(), dep)) { ninjaDeps.push_back( this->GetGlobalNinjaGenerator()->ConvertToNinjaPath(dep)); } @@ -408,9 +404,8 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( this->GetGlobalNinjaGenerator()->MapToNinjaPath()); this->AppendCustomCommandDeps(ccg, ninjaDeps); - for (cmNinjaDeps::iterator i = ninjaOutputs.begin(); i != ninjaOutputs.end(); - ++i) { - this->GetGlobalNinjaGenerator()->SeenCustomCommandOutput(*i); + for (std::string const& ninjaOutput : ninjaOutputs) { + this->GetGlobalNinjaGenerator()->SeenCustomCommandOutput(ninjaOutput); } std::vector cmdLines; @@ -445,10 +440,9 @@ void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc, void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements() { - for (std::vector::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 @@ -511,7 +505,7 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher( std::string launcher = property_value; launcher += " "; - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->CreateRulePlaceholderExpander()); rulePlaceholderExpander->ExpandRuleVariables(this, launcher, vars); diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h index a45e01851..bb16899be 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 #include @@ -38,14 +38,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(); @@ -76,13 +76,13 @@ public: void ComputeObjectFilenames( std::map& mapping, - cmGeneratorTarget const* gt = CM_NULLPTR) CM_OVERRIDE; + cmGeneratorTarget const* gt = nullptr) 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; @@ -105,7 +105,7 @@ private: std::string HomeRelativeOutputPath; - typedef std::map > + typedef std::map> CustomCommandTargetMap; CustomCommandTargetMap CustomCommandTargets; std::vector CustomCommands; diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 9b9d22cf5..e26182a15 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -5,13 +5,12 @@ #include "cmsys/FStream.hxx" #include "cmsys/Terminal.h" #include -#include +#include // IWYU pragma: keep #include #include #include #include "cmAlgorithms.h" -#include "cmCustomCommand.h" #include "cmCustomCommandGenerator.h" #include "cmFileTimeComparison.h" #include "cmGeneratedFileStream.h" @@ -30,7 +29,6 @@ #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 @@ -116,17 +114,16 @@ void cmLocalUnixMakefileGenerator3::Generate() this->Makefile->IsOn("CMAKE_SKIP_ASSEMBLY_SOURCE_RULES"); // Generate the rule files for each target. - std::vector targets = this->GetGeneratorTargets(); + const std::vector& targets = this->GetGeneratorTargets(); cmGlobalUnixMakefileGenerator3* gg = static_cast(this->GlobalGenerator); - for (std::vector::iterator t = targets.begin(); - t != targets.end(); ++t) { - if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { + for (cmGeneratorTarget* target : targets) { + if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } - CM_AUTO_PTR tg( - cmMakefileTargetGenerator::New(*t)); - if (tg.get()) { + std::unique_ptr tg( + cmMakefileTargetGenerator::New(target)); + if (tg) { tg->WriteRuleFiles(); gg->RecordTargetProgress(tg.get()); } @@ -146,7 +143,7 @@ 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 += "/"; @@ -159,12 +156,10 @@ void cmLocalUnixMakefileGenerator3::ComputeObjectFilenames( { // Determine if these object files should use a custom extension char const* custom_ext = gt->GetCustomObjectExtension(); - for (std::map::iterator si = - mapping.begin(); - si != mapping.end(); ++si) { - cmSourceFile const* sf = si->first; + for (auto& si : mapping) { + cmSourceFile const* sf = si.first; bool keptSourceExtension; - si->second = this->GetObjectFileNameWithoutTarget( + si.second = this->GetObjectFileNameWithoutTarget( *sf, gt->ObjectDirectory, &keptSourceExtension, custom_ext); } } @@ -172,10 +167,8 @@ void cmLocalUnixMakefileGenerator3::ComputeObjectFilenames( void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles( std::map& localObjectFiles) { - std::vector targets = this->GetGeneratorTargets(); - for (std::vector::iterator ti = targets.begin(); - ti != targets.end(); ++ti) { - cmGeneratorTarget* gt = *ti; + const std::vector& targets = this->GetGeneratorTargets(); + for (cmGeneratorTarget* gt : targets) { if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; } @@ -189,9 +182,7 @@ void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles( dir += this->GetTargetDirectory(gt); dir += "/"; // Compute the name of each object file. - for (std::vector::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); @@ -210,18 +201,16 @@ void cmLocalUnixMakefileGenerator3::GetIndividualFileTargets( { std::map localObjectFiles; this->GetLocalObjectFiles(localObjectFiles); - for (std::map::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"); } } @@ -270,23 +259,20 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile() // now write out the object rules // for each object file name - for (std::map::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.c_str(), 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::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 +283,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); - this->WriteObjectConvenienceRule(ruleFileStream, - "target to preprocess a source file", - (base + ".i").c_str(), lo->second); - lo->second.HasPreprocessRule = true; + 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(), 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").c_str(), localObjectFile.second); + localObjectFile.second.HasAssembleRule = true; } } @@ -348,16 +334,15 @@ void cmLocalUnixMakefileGenerator3::WriteObjectConvenienceRule( std::vector depends; depends.push_back(output); std::vector 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 commands; - for (std::vector::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 += "/"; @@ -382,20 +367,19 @@ 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 targets = this->GetGeneratorTargets(); + const std::vector& targets = this->GetGeneratorTargets(); std::string localName; - for (std::vector::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 : targets) { + 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(); @@ -411,20 +395,20 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets( 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(); @@ -437,10 +421,10 @@ 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(); @@ -581,9 +565,8 @@ 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::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()); os << cmMakeSafe(tgt) << space << ": " << cmMakeSafe(replace) << "\n"; @@ -718,7 +701,7 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsTop( // Add a fake suffix to keep HP happy. Must be max 32 chars for SGI make. std::vector depends; depends.push_back(".hpux_make_needs_suffix_list"); - this->WriteMakeRule(makefileStream, CM_NULLPTR, ".SUFFIXES", depends, + this->WriteMakeRule(makefileStream, nullptr, ".SUFFIXES", depends, no_commands, false); if (this->IsWatcomWMake()) { // Switch on WMake feature, if an error or interrupt occurs during @@ -892,9 +875,8 @@ void cmLocalUnixMakefileGenerator3::AppendRuleDepends( void cmLocalUnixMakefileGenerator3::AppendCustomDepends( std::vector& depends, const std::vector& ccs) { - for (std::vector::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,11 +884,10 @@ void cmLocalUnixMakefileGenerator3::AppendCustomDepends( void cmLocalUnixMakefileGenerator3::AppendCustomDepend( std::vector& depends, cmCustomCommandGenerator const& ccg) { - for (std::vector::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)) { + if (this->GetRealDependency(d, this->ConfigName, dep)) { depends.push_back(dep); } } @@ -916,9 +897,8 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommands( std::vector& commands, const std::vector& ccs, cmGeneratorTarget* target, std::string const& relative) { - for (std::vector::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 +930,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand( *content << dir; } - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->CreateRulePlaceholderExpander()); // Add each command line to the set of commands. @@ -1089,9 +1069,8 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand( } if (!files.empty()) { fout << "file(REMOVE_RECURSE\n"; - for (std::vector::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"; @@ -1183,10 +1162,10 @@ void cmLocalUnixMakefileGenerator3::AppendEcho( } // Reset the line to emtpy. - line = ""; + line.clear(); // Progress appears only on first line. - progress = CM_NULLPTR; + progress = nullptr; // Terminate on end-of-string. if (*c == '\0') { @@ -1454,13 +1433,10 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies( const char* langStr = mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES"); std::vector langs; cmSystemTools::ExpandListArgument(langStr, langs); - for (std::vector::iterator li = langs.begin(); - li != langs.end(); ++li) { + for (std::string const& lang : langs) { // construct the checker - std::string lang = *li; - // Create the scanner for this language - cmDepends* scanner = CM_NULLPTR; + cmDepends* scanner = nullptr; if (lang == "C" || lang == "CXX" || lang == "RC" || lang == "ASM" || lang == "CUDA") { // TODO: Handle RC (resource files) dependencies correctly. @@ -1562,26 +1538,23 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules( this->WriteDivider(ruleFileStream); ruleFileStream << "# Targets provided globally by CMake.\n" << "\n"; - std::vector targets = this->GetGeneratorTargets(); - std::vector::iterator glIt; - for (glIt = targets.begin(); glIt != targets.end(); ++glIt) { - if ((*glIt)->GetType() == cmStateEnums::GLOBAL_TARGET) { + const std::vector& 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 commands; std::vector 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.insert(depends.end(), gt->GetUtilities().begin(), + gt->GetUtilities().end()); this->AppendEcho(commands, text, cmLocalUnixMakefileGenerator3::EchoGlobal); - cmGeneratorTarget* gt = *glIt; - // Global targets store their rules in pre- and post-build commands. this->AppendCustomDepends(depends, gt->GetPreBuildCommands()); this->AppendCustomDepends(depends, gt->GetPostBuildCommands()); @@ -1728,9 +1701,8 @@ void cmLocalUnixMakefileGenerator3::ClearDependencies(cmMakefile* mf, // dependencies for that target. cmDepends clearer; clearer.SetVerbose(verbose); - for (std::vector::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"; @@ -1802,54 +1774,51 @@ 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 - << "\")\n"; + cmakefileStream << "set(CMAKE_" << implicitLang.first + << "_COMPILER_ID \"" << cid << "\")\n"; } // Build a list of preprocessor definitions for the target. std::set defines; - this->AddCompileDefinitions(defines, target, this->ConfigName, l->first); + this->AddCompileDefinitions(defines, target, this->ConfigName, + implicitLang.first); 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::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 +1827,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 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(); cmEraseIf(includes, ::NotInProjectDir(sourceDir, binaryDir)); } - for (std::vector::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 +1860,8 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo( } if (!transformRules.empty()) { cmakefileStream << "set(CMAKE_INCLUDE_TRANSFORMS\n"; - for (std::vector::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"; } @@ -2004,10 +1971,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 = '\\'; } } } @@ -2106,7 +2072,7 @@ 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(), prefix)); + [&prefix](std::string const& s) { return prefix + s; }); } } diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index f64409cba..b149524b6 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" @@ -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 @@ -88,9 +88,8 @@ public: 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; + void AppendFlags(std::string& flags, const std::string& newFlags) override; + void AppendFlags(std::string& flags, const char* newFlags) override; // append an echo command enum EchoColor @@ -108,14 +107,13 @@ public: std::string Arg; }; void AppendEcho(std::vector& 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& commands, @@ -130,10 +128,10 @@ 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 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); @@ -238,11 +236,11 @@ protected: cmGeneratorTarget* target, std::string const& relative, bool echo_comment = false, - std::ostream* content = CM_NULLPTR); + std::ostream* content = nullptr); void AppendCleanCommand(std::vector& commands, const std::vector& files, cmGeneratorTarget* target, - const char* filename = CM_NULLPTR); + const char* filename = nullptr); // Helper methods for dependeny updates. bool ScanDependencies( @@ -255,7 +253,7 @@ private: void ComputeObjectFilenames( std::map& mapping, - cmGeneratorTarget const* gt = CM_NULLPTR) CM_OVERRIDE; + cmGeneratorTarget const* gt = nullptr) override; friend class cmMakefileTargetGenerator; friend class cmMakefileExecutableTargetGenerator; @@ -272,7 +270,7 @@ private: cmGeneratorTarget* Target; std::string Language; LocalObjectEntry() - : Target(CM_NULLPTR) + : Target(nullptr) , Language() { } diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx index 85d4a73b7..5e81514d4 100644 --- a/Source/cmLocalVisualStudio10Generator.cxx +++ b/Source/cmLocalVisualStudio10Generator.cxx @@ -17,7 +17,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; } } @@ -60,8 +65,8 @@ cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator() void cmLocalVisualStudio10Generator::Generate() { - std::vector tgts = this->GetGeneratorTargets(); - for (std::vector::iterator l = tgts.begin(); + const std::vector& tgts = this->GetGeneratorTargets(); + for (std::vector::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; diff --git a/Source/cmLocalVisualStudio10Generator.h b/Source/cmLocalVisualStudio10Generator.h index e57dd8f20..4cd56dde3 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 diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index dd08e5bdb..d8030b7fb 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -62,8 +62,8 @@ cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator() void cmLocalVisualStudio7Generator::AddHelperCommands() { // Now create GUIDs for targets - std::vector tgts = this->GetGeneratorTargets(); - for (std::vector::iterator l = tgts.begin(); + const std::vector& tgts = this->GetGeneratorTargets(); + for (std::vector::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; @@ -91,8 +91,9 @@ void cmLocalVisualStudio7Generator::AddCMakeListsRules() // specification source changes. if (cmSourceFile* sf = this->CreateVCProjBuildRule()) { // Add the rule to targets that need it. - std::vector tgts = this->GetGeneratorTargets(); - for (std::vector::iterator l = tgts.begin(); + const std::vector& tgts = + this->GetGeneratorTargets(); + for (std::vector::const_iterator l = tgts.begin(); l != tgts.end(); ++l) { if ((*l)->GetType() == cmStateEnums::GLOBAL_TARGET) { continue; @@ -110,8 +111,8 @@ 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 tgts = this->GetGeneratorTargets(); - for (std::vector::iterator l = tgts.begin(); + const std::vector& tgts = this->GetGeneratorTargets(); + for (std::vector::const_iterator l = tgts.begin(); l != tgts.end(); l++) { if ((*l)->GetType() == cmStateEnums::GLOBAL_TARGET) { std::vector no_depends; @@ -120,7 +121,7 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() 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 += "/"; @@ -150,10 +151,10 @@ void cmLocalVisualStudio7Generator::WriteProjectFiles() } // Get the set of targets in this directory. - std::vector tgts = this->GetGeneratorTargets(); + const std::vector& tgts = this->GetGeneratorTargets(); // Create the project file for each target. - for (std::vector::iterator l = tgts.begin(); + for (std::vector::const_iterator l = tgts.begin(); l != tgts.end(); l++) { if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) { continue; @@ -525,6 +526,7 @@ 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", "", @@ -1451,8 +1453,8 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo( } if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) { cmGeneratorExpression ge; - CM_AUTO_PTR cge = ge.Parse(cflags); - fc.CompileFlags = cge->Evaluate(lg, *i); + std::unique_ptr cge = ge.Parse(cflags); + fc.CompileFlags = cge->Evaluate(lg, *i, false, gt); needfc = true; } if (lg->FortranProject) { @@ -1589,7 +1591,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup( // If the group has a name, write the header. std::string name = sg->GetName(); - if (name != "") { + if (!name.empty()) { this->WriteVCProjBeginGroup(fout, name.c_str(), ""); } @@ -1707,7 +1709,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup( } // If the group has a name, write the footer. - if (name != "") { + if (!name.empty()) { this->WriteVCProjEndGroup(fout); } @@ -1847,7 +1849,7 @@ void cmLocalVisualStudio7Generator::OutputTargetRules( if (!addedPrelink) { event.Write(target->GetPreLinkCommands()); } - CM_AUTO_PTR pcc( + std::unique_ptr pcc( this->MaybeCreateImplibDir(target, configName, this->FortranProject)); if (pcc.get()) { event.Write(*pcc); @@ -2004,7 +2006,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFooter( i != props.end(); ++i) { if (i->find("VS_GLOBAL_") == 0) { std::string name = i->substr(10); - if (name != "") { + if (!name.empty()) { /* clang-format off */ fout << "\t\tGUID = 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..7a77574fa 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 #include diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 41025af6c..bbb91e04b 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -78,12 +78,12 @@ void cmLocalVisualStudioGenerator::ComputeObjectFilenames( } } -CM_AUTO_PTR +std::unique_ptr cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* target, const std::string& config, bool isFortran) { - CM_AUTO_PTR pcc; + std::unique_ptr pcc; // If an executable exports symbols then VS wants to create an // import library but forgets to create the output directory. @@ -135,7 +135,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 +191,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. // diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h index 85fb8a511..cba24fed7 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 -#include +#include // IWYU pragma: keep #include #include "cmGlobalVisualStudioGenerator.h" #include "cmLocalGenerator.h" -#include "cm_auto_ptr.hxx" class cmCustomCommand; class cmCustomCommandGenerator; @@ -56,9 +55,8 @@ protected: virtual bool CustomCommandUseLocal() const { return false; } /** Construct a custom command to make exe import lib dir. */ - CM_AUTO_PTR MaybeCreateImplibDir(cmGeneratorTarget* target, - const std::string& config, - bool isFortran); + std::unique_ptr MaybeCreateImplibDir( + cmGeneratorTarget* target, const std::string& config, bool isFortran); }; #endif diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx index 739ef4367..853e66c23 100644 --- a/Source/cmLocalXCodeGenerator.cxx +++ b/Source/cmLocalXCodeGenerator.cxx @@ -42,10 +42,9 @@ void cmLocalXCodeGenerator::Generate() { cmLocalGenerator::Generate(); - std::vector targets = this->GetGeneratorTargets(); - for (std::vector::iterator iter = targets.begin(); - iter != targets.end(); ++iter) { - (*iter)->HasMacOSXRpathInstallNameDir(""); + const std::vector& targets = this->GetGeneratorTargets(); + for (auto target : targets) { + target->HasMacOSXRpathInstallNameDir(""); } } @@ -53,10 +52,9 @@ void cmLocalXCodeGenerator::GenerateInstallRules() { cmLocalGenerator::GenerateInstallRules(); - std::vector targets = this->GetGeneratorTargets(); - for (std::vector::iterator iter = targets.begin(); - iter != targets.end(); ++iter) { - (*iter)->HasMacOSXRpathInstallNameDir(""); + const std::vector& targets = this->GetGeneratorTargets(); + for (auto target : targets) { + target->HasMacOSXRpathInstallNameDir(""); } } @@ -69,10 +67,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 counts; - for (std::map::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 +78,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..8c9596f85 100644 --- a/Source/cmLocalXCodeGenerator.h +++ b/Source/cmLocalXCodeGenerator.h @@ -27,16 +27,16 @@ public: ///! 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) override; + void Generate() override; virtual void GenerateInstallRules(); - virtual void ComputeObjectFilenames( + void ComputeObjectFilenames( std::map& mapping, - cmGeneratorTarget const* gt = 0); + cmGeneratorTarget const* gt = nullptr) override; private: }; diff --git a/Source/cmLocale.h b/Source/cmLocale.h index 9f90a3a99..174f0f0f2 100644 --- a/Source/cmLocale.h +++ b/Source/cmLocale.h @@ -3,7 +3,7 @@ #ifndef cmLocale_h #define cmLocale_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -14,7 +14,7 @@ class cmLocaleRAII public: cmLocaleRAII() - : OldLocale(setlocale(LC_CTYPE, CM_NULLPTR)) + : OldLocale(setlocale(LC_CTYPE, nullptr)) { setlocale(LC_CTYPE, ""); } diff --git a/Source/cmMSVC60LinkLineComputer.h b/Source/cmMSVC60LinkLineComputer.h index f2892d53f..31223ecd4 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 @@ -21,8 +21,7 @@ public: cmMSVC60LinkLineComputer(cmOutputConverter* outputConverter, cmStateDirectory const& stateDir); - std::string ConvertToLinkReference(std::string const& input) const - CM_OVERRIDE; + std::string ConvertToLinkReference(std::string const& input) const override; }; #endif diff --git a/Source/cmMachO.cxx b/Source/cmMachO.cxx index a4350f7ce..7294c1cbf 100644 --- a/Source/cmMachO.cxx +++ b/Source/cmMachO.cxx @@ -134,7 +134,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 +251,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 +264,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 +282,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 +312,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..aa17c6a77 100644 --- a/Source/cmMachO.h +++ b/Source/cmMachO.h @@ -3,7 +3,7 @@ #ifndef cmMachO_h #define cmMachO_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index a6a9ea316..74a1da00e 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -19,12 +19,12 @@ public: cmMacroHelperCommand() {} ///! clean up any memory allocated by the macro - ~cmMacroHelperCommand() CM_OVERRIDE {} + ~cmMacroHelperCommand() 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 +40,10 @@ public: * the CMakeLists.txt file. */ bool InvokeInitialPass(const std::vector& args, - cmExecutionStatus&) CM_OVERRIDE; + cmExecutionStatus&) override; bool InitialPass(std::vector const&, - cmExecutionStatus&) CM_OVERRIDE + cmExecutionStatus&) override { return false; } @@ -98,20 +98,18 @@ bool cmMacroHelperCommand::InvokeInitialPass( // 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::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,8 +129,8 @@ bool cmMacroHelperCommand::InvokeInitialPass( } } } - arg.Delim = k->Delim; - arg.Line = k->Line; + arg.Delim = k.Delim; + arg.Line = k.Line; newLFF.Arguments.push_back(arg); } cmExecutionStatus status; diff --git a/Source/cmMacroCommand.h b/Source/cmMacroCommand.h index 0d35fe06e..d967388bf 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 #include @@ -19,10 +19,10 @@ class cmMacroFunctionBlocker : public cmFunctionBlocker { public: cmMacroFunctionBlocker() { this->Depth = 0; } - ~cmMacroFunctionBlocker() CM_OVERRIDE {} + ~cmMacroFunctionBlocker() 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 Args; std::vector Functions; @@ -36,14 +36,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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 608b18a46..5643c978d 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -7,6 +7,7 @@ #include #include #include +#include // IWYU pragma: keep #include #include #include @@ -37,7 +38,6 @@ #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" @@ -66,8 +66,8 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator, 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/_.+-]+{"); @@ -87,12 +87,10 @@ 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(); @@ -208,15 +206,13 @@ void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const msg << lff.Name << "("; bool expand = this->GetCMakeInstance()->GetTraceExpand(); std::string temp; - for (std::vector::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 << " "; } @@ -268,7 +264,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, // Lookup the command prototype. if (cmCommand* proto = this->GetState()->GetCommand(name)) { // Clone the prototype. - CM_AUTO_PTR pcmd(proto->Clone()); + std::unique_ptr pcmd(proto->Clone()); pcmd->SetMakefile(this); // Decide whether to invoke the command. @@ -588,11 +584,13 @@ void cmMakefile::EnforceDirectoryLevelRules() const void cmMakefile::AddEvaluationFile( const std::string& inputFile, - CM_AUTO_PTR outputName, - CM_AUTO_PTR condition, bool inputIsContent) + std::unique_ptr outputName, + std::unique_ptr 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 @@ -641,9 +639,8 @@ void cmMakefile::FinalPass() // give all the commands a chance to do something // after the file has been parsed before generation - for (std::vector::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. @@ -740,9 +737,8 @@ void cmMakefile::AddCustomCommandToTarget( } // Always create the byproduct sources and mark them generated. - for (std::vector::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"); } } @@ -780,23 +776,21 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( // 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; + 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 +804,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); } @@ -843,15 +837,13 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( } // Always create the output sources and mark them generated. - for (std::vector::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)) { out->SetProperty("GENERATED", "1"); } } - for (std::vector::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"); } } @@ -880,9 +872,8 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( void cmMakefile::UpdateOutputToSourceMap( std::vector const& outputs, cmSourceFile* source) { - for (std::vector::const_iterator o = outputs.begin(); - o != outputs.end(); ++o) { - this->UpdateOutputToSourceMap(*o, source); + for (std::string const& o : outputs) { + this->UpdateOutputToSourceMap(o, source); } } @@ -934,7 +925,7 @@ void cmMakefile::AddCustomCommandOldStyle( std::vector no_byproducts; this->AddCustomCommandToTarget(target, no_byproducts, depends, commandLines, cmTarget::POST_BUILD, comment, - CM_NULLPTR); + nullptr); return; } @@ -942,24 +933,23 @@ void cmMakefile::AddCustomCommandOldStyle( cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|" "rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|" "hm|hpp|hxx|in|txx|inl)$"); - for (std::vector::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 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), @@ -1063,9 +1053,8 @@ cmTarget* cmMakefile::AddUtilityCommand( } // Always create the byproduct sources and mark them generated. - for (std::vector::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)) { out->SetProperty("GENERATED", "1"); } } @@ -1227,15 +1216,17 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) parent->GetProperty("COMPILE_DEFINITIONS")); std::vector configs; this->GetConfigurations(configs); - for (std::vector::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")); @@ -1389,10 +1380,8 @@ void cmMakefile::Configure() if (this->IsRootMakefile()) { bool hasVersion = false; // search for the right policy command - for (std::vector::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 (cmSystemTools::LowerCase(func.Name) == "cmake_minimum_required") { hasVersion = true; break; } @@ -1418,10 +1407,8 @@ void cmMakefile::Configure() allowedCommands.insert("option"); allowedCommands.insert("message"); isProblem = false; - for (std::vector::iterator i = - listFile.Functions.begin(); - i != listFile.Functions.end(); ++i) { - std::string name = cmSystemTools::LowerCase(i->Name); + for (cmListFileFunction const& func : listFile.Functions) { + std::string name = cmSystemTools::LowerCase(func.Name); if (allowedCommands.find(name) == allowedCommands.end()) { isProblem = true; break; @@ -1440,10 +1427,8 @@ void cmMakefile::Configure() } bool hasProject = false; // search for a project command - for (std::vector::iterator i = - listFile.Functions.begin(); - i != listFile.Functions.end(); ++i) { - if (cmSystemTools::LowerCase(i->Name) == "project") { + for (cmListFileFunction const& func : listFile.Functions) { + if (cmSystemTools::LowerCase(func.Name) == "project") { hasProject = true; break; } @@ -1575,9 +1560,8 @@ std::vector cmMakefile::GetImportedTargets() const { std::vector 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 +1584,8 @@ void cmMakefile::AddIncludeDirectories(const std::vector& 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 +1598,8 @@ void cmMakefile::AddSystemIncludeDirectories(const std::set& 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); } } @@ -1664,7 +1646,7 @@ 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())) { files[cc] = cmSystemTools::CollapseFullPath(files[cc]); @@ -1757,7 +1739,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 } @@ -1786,14 +1768,13 @@ void cmMakefile::AddGlobalLinkInformation(cmTarget& target) std::vector linkDirs; cmSystemTools::ExpandListArgument(linkDirsProp, linkDirs); - for (std::vector::iterator j = linkDirs.begin(); - j != linkDirs.end(); ++j) { - std::string newdir = *j; + for (std::string const& linkDir : linkDirs) { + std::string newdir = linkDir; // remove trailing slashes - if (*j->rbegin() == '/') { - newdir = j->substr(0, j->size() - 1); + if (*linkDir.rbegin() == '/') { + newdir = linkDir.substr(0, linkDir.size() - 1); } - target.AddLinkDirectory(*j); + target.AddLinkDirectory(linkDir); } } @@ -1886,29 +1867,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::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& outputs = - (*i)->GetCustomCommand()->GetOutputs(); - for (std::vector::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( @@ -1924,31 +1902,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& 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::const_iterator sgIt = - this->SourceGroups.begin(); - sgIt != this->SourceGroups.end(); ++sgIt) { - std::string sgName = sgIt->GetName(); + for (cmSourceGroup const& srcGroup : this->SourceGroups) { + std::string sgName = srcGroup.GetName(); if (sgName == name[0]) { - sg = const_cast(&(*sgIt)); + sg = const_cast(&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) { + if (sg == nullptr) { break; } } @@ -1966,14 +1942,14 @@ void cmMakefile::AddSourceGroup(const std::string& name, const char* regex) void cmMakefile::AddSourceGroup(const std::vector& name, const char* regex) { - cmSourceGroup* sg = CM_NULLPTR; + cmSourceGroup* sg = nullptr; std::vector currentName; int i = 0; const int lastElement = static_cast(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; } } @@ -2001,14 +1977,65 @@ void cmMakefile::AddSourceGroup(const std::vector& name, } // build the whole source group path for (++i; i <= lastElement; ++i) { - sg->AddChild( - cmSourceGroup(name[i].c_str(), CM_NULLPTR, sg->GetFullName())); + sg->AddChild(cmSourceGroup(name[i].c_str(), nullptr, sg->GetFullName())); sg = sg->LookupChild(name[i].c_str()); } sg->SetGroupRegex(regex); } +cmSourceGroup* cmMakefile::GetOrCreateSourceGroup( + const std::vector& 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 char* source, std::vector& groups) const +{ + // First search for a group that lists the file explicitly. + for (std::vector::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::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 static bool mightExpandVariablesCMP0019(const char* s) @@ -2041,9 +2068,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; @@ -2190,9 +2216,9 @@ bool cmMakefile::PlatformIsAppleIos() const "iphonesimulator", "watchos", "watchsimulator", }; - for (size_t i = 0; i < sizeof(embedded) / sizeof(embedded[0]); ++i) { - if (sdkRoot.find(embedded[i]) == 0 || - sdkRoot.find(std::string("/") + embedded[i]) != std::string::npos) { + for (std::string const& i : embedded) { + if (sdkRoot.find(i) == 0 || + sdkRoot.find(std::string("/") + i) != std::string::npos) { return true; } } @@ -2252,7 +2278,7 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const } } #endif - return def != CM_NULLPTR; + return def != nullptr; } const char* cmMakefile::GetDefinition(const std::string& name) const @@ -2423,7 +2449,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(); @@ -2561,7 +2587,7 @@ 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"; @@ -2617,7 +2643,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. @@ -2817,40 +2843,6 @@ std::string cmMakefile::GetConfigurations(std::vector& 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& groups) const -{ - // First search for a group that lists the file explicitly. - for (std::vector::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::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) { @@ -2883,7 +2875,7 @@ void cmMakefile::PopFunctionBlockerBarrier(bool reportError) FunctionBlockersType::size_type barrier = this->FunctionBlockerBarriers.back(); while (this->FunctionBlockers.size() > barrier) { - CM_AUTO_PTR fb(this->FunctionBlockers.back()); + std::unique_ptr fb(this->FunctionBlockers.back()); this->FunctionBlockers.pop_back(); if (reportError) { // Report the context in which the unclosed block was opened. @@ -2948,23 +2940,22 @@ bool cmMakefile::ExpandArguments(std::vector const& inArgs, if (!filename) { filename = efp.c_str(); } - std::vector::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 +2972,28 @@ bool cmMakefile::ExpandArguments( if (!filename) { filename = efp.c_str(); } - std::vector::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.push_back(cmExpandedCommandArgument(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) { + if (i.Delim == cmListFileArgument::Quoted) { outArgs.push_back(cmExpandedCommandArgument(value, true)); } else { std::vector 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.push_back(cmExpandedCommandArgument(stringArg, false)); } } } @@ -3020,7 +3010,7 @@ void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb) this->FunctionBlockers.push_back(fb); } -CM_AUTO_PTR cmMakefile::RemoveFunctionBlocker( +std::unique_ptr cmMakefile::RemoveFunctionBlocker( cmFunctionBlocker* fb, const cmListFileFunction& lff) { // Find the function blocker stack barrier for the current scope. @@ -3053,11 +3043,11 @@ CM_AUTO_PTR cmMakefile::RemoveFunctionBlocker( } cmFunctionBlocker* b = *pos; this->FunctionBlockers.erase(pos); - return CM_AUTO_PTR(b); + return std::unique_ptr(b); } } - return CM_AUTO_PTR(); + return std::unique_ptr(); } const char* cmMakefile::GetHomeDirectory() const @@ -3093,15 +3083,12 @@ void cmMakefile::SetArgcArgv(const std::vector& args) cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const { cmSourceFileLocation sfl(this, sourceName); - for (std::vector::const_iterator sfi = - this->SourceFiles.begin(); - sfi != this->SourceFiles.end(); ++sfi) { - cmSourceFile* sf = *sfi; + for (cmSourceFile* sf : this->SourceFiles) { if (sf->Matches(sfl)) { return sf; } } - return CM_NULLPTR; + return nullptr; } cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName, @@ -3147,12 +3134,11 @@ void cmMakefile::EnableLanguage(std::vector const& lang, std::vector langs; std::vector langsRC; langs.reserve(lang.size()); - for (std::vector::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()) { @@ -3200,8 +3186,8 @@ int cmMakefile::TryCompile(const std::string& srcdir, // do a configure cm.SetHomeDirectory(srcdir); cm.SetHomeOutputDirectory(bindir); - cm.SetGeneratorPlatform(this->GetCMakeInstance()->GetGeneratorPlatform()); - cm.SetGeneratorToolset(this->GetCMakeInstance()->GetGeneratorToolset()); + cm.SetGeneratorPlatform(this->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM")); + cm.SetGeneratorToolset(this->GetSafeDefinition("CMAKE_GENERATOR_TOOLSET")); cm.LoadCache(); if (!gg->IsMultiConfig()) { if (const char* config = @@ -3302,7 +3288,7 @@ cmVariableWatch* cmMakefile::GetVariableWatch() const this->GetCMakeInstance()->GetVariableWatch()) { return this->GetCMakeInstance()->GetVariableWatch(); } - return CM_NULLPTR; + return nullptr; } #endif @@ -3346,9 +3332,7 @@ std::string cmMakefile::GetModulesFile(const char* filename) const cmSystemTools::ExpandListArgument(cmakeModulePath, modulePath); // Look through the possible module directories. - for (std::vector::iterator i = modulePath.begin(); - i != modulePath.end(); ++i) { - std::string itempl = *i; + for (std::string itempl : modulePath) { cmSystemTools::ConvertToUnixSlashes(itempl); itempl += "/"; itempl += filename; @@ -3365,7 +3349,7 @@ std::string cmMakefile::GetModulesFile(const char* filename) const moduleInCMakeRoot += filename; cmSystemTools::ConvertToUnixSlashes(moduleInCMakeRoot); if (!cmSystemTools::FileExists(moduleInCMakeRoot.c_str())) { - moduleInCMakeRoot = ""; + moduleInCMakeRoot.clear(); } // Normally, prefer the files found in CMAKE_MODULE_PATH. Only when the file @@ -3432,18 +3416,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,7 +3451,7 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output, } // Perform variable replacements. - this->ExpandVariablesInString(output, escapeQuotes, true, atOnly, CM_NULLPTR, + this->ExpandVariablesInString(output, escapeQuotes, true, atOnly, nullptr, -1, true, true); } @@ -3545,7 +3533,7 @@ 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; } @@ -3603,7 +3591,7 @@ cmTarget* cmMakefile::FindLocalNonAliasTarget(const std::string& name) const if (i != this->Targets.end()) { return &i->second; } - return CM_NULLPTR; + return nullptr; } cmTest* cmMakefile::CreateTest(const std::string& testName) @@ -3625,7 +3613,7 @@ cmTest* cmMakefile::GetTest(const std::string& testName) const if (mi != this->Tests.end()) { return mi->second; } - return CM_NULLPTR; + return nullptr; } void cmMakefile::AddCMakeDependFilesFromUser() @@ -3634,14 +3622,13 @@ void cmMakefile::AddCMakeDependFilesFromUser() if (const char* deps_str = this->GetProperty("CMAKE_CONFIGURE_DEPENDS")) { cmSystemTools::ExpandListArgument(deps_str, deps); } - for (std::vector::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.c_str())) { + this->AddCMakeDependFile(dep); } else { std::string f = this->GetCurrentSourceDirectory(); f += "/"; - f += *i; + f += dep; this->AddCMakeDependFile(f); } } @@ -3717,7 +3704,7 @@ cmTarget* cmMakefile::AddImportedTarget(const std::string& name, bool global) { // Create the target. - CM_AUTO_PTR target( + std::unique_ptr target( new cmTarget(name, type, global ? cmTarget::VisibilityImportedGlobally : cmTarget::VisibilityImported, this)); @@ -3896,16 +3883,6 @@ bool cmMakefile::EnforceUniqueDir(const std::string& srcPath, return false; } -void cmMakefile::AddQtUiFileWithOptions(cmSourceFile* sf) -{ - this->QtUiFilesWithOptions.push_back(sf); -} - -std::vector 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", @@ -4093,10 +4070,10 @@ 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 @@ -4204,7 +4181,7 @@ const char* cmMakefile::CompileFeaturesAvailable(const std::string& lang, this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), this->Backtrace); } - return CM_NULLPTR; + return nullptr; } const char* featuresKnown = @@ -4227,7 +4204,7 @@ const char* cmMakefile::CompileFeaturesAvailable(const std::string& lang, this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), this->Backtrace); } - return CM_NULLPTR; + return nullptr; } return featuresKnown; } @@ -4375,6 +4352,18 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target, cmStrCmp(existingCxxStandard)) : cmArrayEnd(CXX_STANDARDS); + if (needCxx17 && + existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), + cmArrayEnd(CXX_STANDARDS), + cmStrCmp("17"))) { + return false; + } + if (needCxx14 && + existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), + cmArrayEnd(CXX_STANDARDS), + cmStrCmp("14"))) { + return false; + } if (needCxx11 && existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index e65ba468f..0273f5bae 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -3,15 +3,17 @@ #ifndef cmMakefile_h #define cmMakefile_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmsys/RegularExpression.hxx" #include #include +#include // IWYU pragma: keep #include #include #include #include +#include #include #include "cmAlgorithms.h" @@ -21,8 +23,6 @@ #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) @@ -92,7 +92,7 @@ public: * Remove the function blocker whose scope ends with the given command. * This returns ownership of the function blocker object. */ - CM_AUTO_PTR RemoveFunctionBlocker( + std::unique_ptr RemoveFunctionBlocker( cmFunctionBlocker* fb, const cmListFileFunction& lff); /** @@ -187,24 +187,26 @@ public: * Add a utility to the build. A utiltity target is a command that * is run every time the target is built. */ - cmTarget* AddUtilityCommand( - const std::string& utilityName, bool excludeFromAll, - const std::vector& 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::vector& 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 char* workingDirectory, const std::vector& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle = true, - const char* comment = CM_NULLPTR, bool uses_terminal = false, + const char* comment = nullptr, bool uses_terminal = false, bool command_expand_lists = false); cmTarget* AddUtilityCommand( const std::string& utilityName, bool excludeFromAll, const char* workingDirectory, const std::vector& byproducts, const std::vector& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle = true, - const char* comment = CM_NULLPTR, bool uses_terminal = false, + const char* comment = nullptr, bool uses_terminal = false, bool command_expand_lists = false); /** @@ -268,21 +270,6 @@ 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& name, - const char* regex = CM_NULLPTR); - -#endif - //@{ /** * Set, Push, Pop policy values for CMake. @@ -474,6 +461,36 @@ public: * Get the source group */ cmSourceGroup* GetSourceGroup(const std::vector& 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& name, + const char* regex = nullptr); + + /** + * Get and existing or create a new source group. + */ + cmSourceGroup* GetOrCreateSourceGroup( + const std::vector& 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 char* source, + std::vector& groups) const; #endif /** @@ -521,7 +538,7 @@ public: 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, + const char* filename = nullptr, long line = -1, bool removeEmpty = false, bool replaceAt = false) const; @@ -550,14 +567,6 @@ public: 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& groups) const; -#endif - /** * Print a command's invocation */ @@ -594,11 +603,11 @@ public: */ bool ExpandArguments(std::vector const& inArgs, std::vector& outArgs, - const char* filename = CM_NULLPTR) const; + const char* filename = nullptr) const; bool ExpandArguments(std::vector const& inArgs, std::vector& outArgs, - const char* filename = CM_NULLPTR) const; + const char* filename = nullptr) const; /** * Get the instance @@ -614,7 +623,6 @@ public: { return this->SourceFiles; } - std::vector& GetSourceFiles() { return this->SourceFiles; } /** * Is there a source file that has the provided source file as an output? @@ -736,9 +744,6 @@ public: cmStringRange GetCompileDefinitionsEntries() const; cmBacktraceRange GetCompileDefinitionsBacktraces() const; - void AddQtUiFileWithOptions(cmSourceFile* sf); - std::vector GetQtUiFilesWithOptions() const; - std::set const& GetSystemIncludeDirectories() const { return this->SystemIncludeDirectories; @@ -747,7 +752,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 +781,11 @@ public: void EnforceDirectoryLevelRules() const; - void AddEvaluationFile(const std::string& inputFile, - CM_AUTO_PTR outputName, - CM_AUTO_PTR condition, - bool inputIsContent); + void AddEvaluationFile( + const std::string& inputFile, + std::unique_ptr outputName, + std::unique_ptr condition, + bool inputIsContent); std::vector GetEvaluationFiles() const; std::vector GetExportBuildFileGenerators() @@ -871,7 +877,7 @@ private: friend class cmParseFileScope; std::vector ImportedTargetsOwned; - typedef CM_UNORDERED_MAP TargetMap; + typedef std::unordered_map TargetMap; TargetMap ImportedTargets; // Internal policy stack management. @@ -909,7 +915,7 @@ private: cmSourceFile* LinearGetSourceFileWithOutput(const std::string& cname) const; // A map for fast output to input look up. - typedef CM_UNORDERED_MAP OutputToSourceMap; + typedef std::unordered_map OutputToSourceMap; OutputToSourceMap OutputToSource; void UpdateOutputToSourceMap(std::vector const& outputs, @@ -917,14 +923,12 @@ private: void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source); - std::vector 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; diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 359b9fdbb..801f72ab6 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -3,6 +3,7 @@ #include "cmMakefileExecutableTargetGenerator.h" #include +#include // IWYU pragma: keep #include #include #include @@ -23,7 +24,6 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator( @@ -193,7 +193,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule( // Set path conversion for link script shells. this->LocalGenerator->SetLinkScriptShell(useLinkScript); - CM_AUTO_PTR linkLineComputer( + std::unique_ptr linkLineComputer( new cmLinkLineDeviceComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -251,16 +251,15 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule( launcher += " "; } - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->LocalGenerator->CreateRulePlaceholderExpander()); // Expand placeholders in the commands. rulePlaceholderExpander->SetTargetImpLib(targetOutputReal); - for (std::vector::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. @@ -284,7 +283,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule( commands1.clear(); // Write the build rule. - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, targetOutputReal, depends, commands, false); @@ -449,7 +448,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) linkFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig)); { - CM_AUTO_PTR linkLineComputer( + std::unique_ptr linkLineComputer( this->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -539,7 +538,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) // Set path conversion for link script shells. this->LocalGenerator->SetLinkScriptShell(useLinkScript); - CM_AUTO_PTR linkLineComputer( + std::unique_ptr linkLineComputer( this->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -619,7 +618,7 @@ 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); } @@ -633,16 +632,15 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) launcher += " "; } - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->LocalGenerator->CreateRulePlaceholderExpander()); // Expand placeholders in the commands. rulePlaceholderExpander->SetTargetImpLib(targetOutPathImport); - for (std::vector::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. @@ -687,7 +685,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 +696,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); } 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 @@ -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..80c62d10f 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -3,6 +3,7 @@ #include "cmMakefileLibraryTargetGenerator.h" #include +#include // IWYU pragma: keep #include #include @@ -22,7 +23,6 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator( @@ -117,7 +117,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); @@ -199,7 +199,7 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink) this->LocalGenerator->AddConfigVariableFlags( extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->ConfigName); - CM_AUTO_PTR linkLineComputer( + std::unique_ptr linkLineComputer( this->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -248,7 +248,7 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink) this->LocalGenerator->AddConfigVariableFlags( extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->ConfigName); - CM_AUTO_PTR linkLineComputer( + std::unique_ptr linkLineComputer( this->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -348,7 +348,7 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules( std::string linkLibs; if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) { - CM_AUTO_PTR linkLineComputer( + std::unique_ptr linkLineComputer( new cmLinkLineDeviceComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -410,7 +410,7 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules( launcher += " "; } - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->LocalGenerator->CreateRulePlaceholderExpander()); // Construct the main link rule and expand placeholders. @@ -419,11 +419,10 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules( cmSystemTools::ExpandListArgument(linkRule, real_link_commands); // Expand placeholders. - for (std::vector::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); @@ -454,7 +453,7 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules( std::vector 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. @@ -755,7 +754,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( std::string linkLibs; if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) { - CM_AUTO_PTR linkLineComputer( + std::unique_ptr linkLineComputer( this->CreateLinkLineComputer( this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory())); @@ -874,7 +873,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( launcher += " "; } - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->LocalGenerator->CreateRulePlaceholderExpander()); // Construct the main link rule and expand placeholders. rulePlaceholderExpander->SetTargetImpLib(targetOutPathImport); @@ -897,10 +896,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( std::vector::iterator osi = object_strings.begin(); { vars.Objects = osi->c_str(); - for (std::vector::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); @@ -909,10 +906,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( // Append to the archive with the other object sets. for (++osi; osi != object_strings.end(); ++osi) { vars.Objects = osi->c_str(); - for (std::vector::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); @@ -920,10 +915,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( } // Finish the archive. vars.Objects = ""; - for (std::vector::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. @@ -939,17 +932,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); } // Expand placeholders. - for (std::vector::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); } } @@ -1008,7 +1000,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( } // 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. diff --git a/Source/cmMakefileLibraryTargetGenerator.h b/Source/cmMakefileLibraryTargetGenerator.h index da1d8b65c..02fa029cd 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(); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index a4511b63b..7db010c24 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 // IWYU pragma: keep #include #include #include @@ -27,17 +28,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(target->GetLocalGenerator()); @@ -60,7 +60,7 @@ cmMakefileTargetGenerator::~cmMakefileTargetGenerator() cmMakefileTargetGenerator* cmMakefileTargetGenerator::New( cmGeneratorTarget* tgt) { - cmMakefileTargetGenerator* result = CM_NULLPTR; + cmMakefileTargetGenerator* result = nullptr; switch (tgt->GetType()) { case cmStateEnums::EXECUTABLE: @@ -134,12 +134,12 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() if (const char* additional_clean_files = this->Makefile->GetProperty("ADDITIONAL_MAKE_CLEAN_FILES")) { cmGeneratorExpression ge; - CM_AUTO_PTR cge = + std::unique_ptr cge = ge.Parse(additional_clean_files); cmSystemTools::ExpandListArgument( cge->Evaluate(this->LocalGenerator, config, false, this->GeneratorTarget, - CM_NULLPTR, CM_NULLPTR), + nullptr, nullptr), this->CleanFiles); } @@ -153,18 +153,16 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() this->GeneratorTarget->GetCustomCommands(customCommands, config); std::string currentBinDir = this->LocalGenerator->GetCurrentBinaryDirectory(); - for (std::vector::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& outputs = ccg.GetOutputs(); - for (std::vector::const_iterator o = outputs.begin(); - o != outputs.end(); ++o) { + for (std::string const& output : outputs) { this->CleanFiles.push_back( - this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, *o)); + this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, + output)); } } } @@ -178,18 +176,14 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() extraSources, this->MacOSXContentGenerator); std::vector externalObjects; this->GeneratorTarget->GetExternalObjects(externalObjects, config); - for (std::vector::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 objectSources; this->GeneratorTarget->GetObjectSources(objectSources, config); - for (std::vector::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); } } @@ -272,28 +266,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::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::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"; } } @@ -337,7 +329,7 @@ void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()( output, cmOutputConverter::SHELL); commands.push_back(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); } @@ -442,7 +434,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( // Add flags from source file properties. if (const char* cflags = source.GetProperty("COMPILE_FLAGS")) { cmGeneratorExpression ge; - CM_AUTO_PTR cge = ge.Parse(cflags); + std::unique_ptr cge = ge.Parse(cflags); const char* evaluatedFlags = cge->Evaluate(this->LocalGenerator, config, false, this->GeneratorTarget); this->LocalGenerator->AppendFlags(flags, evaluatedFlags); @@ -578,7 +570,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( bool const lang_has_assembly = lang_has_preprocessor; bool const lang_can_export_cmds = lang_has_preprocessor; - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->LocalGenerator->CreateRulePlaceholderExpander()); // Construct the compile rules. @@ -633,8 +625,11 @@ 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 (iwyu && *iwyu) { run_iwyu += " --iwyu="; run_iwyu += this->LocalGenerator->EscapeForShell(iwyu); @@ -647,7 +642,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; } @@ -657,17 +657,16 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( } // Maybe insert a compiler launcher like ccache or distcc - if (!compileCommands.empty() && (lang == "C" || lang == "CXX")) { + if (!compileCommands.empty() && + (lang == "C" || lang == "CXX" || lang == "CUDA")) { std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER"; const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop); if (clauncher && *clauncher) { std::vector launcher_cmd; cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true); - for (std::vector::iterator i = launcher_cmd.begin(), - e = launcher_cmd.end(); - i != e; ++i) { - *i = this->LocalGenerator->EscapeForShell(*i); + for (std::string& i : launcher_cmd) { + i = this->LocalGenerator->EscapeForShell(i); } std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " "; compileCommands.front().insert(0, run_launcher); @@ -685,11 +684,10 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( } // Expand placeholders in the commands. - for (std::vector::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. @@ -710,7 +708,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( } // 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 && @@ -750,11 +748,10 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( vars.PreprocessedSource = shellObjI.c_str(); // Expand placeholders in the commands. - for (std::vector::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( @@ -769,7 +766,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( commands.push_back(cmd); } - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, relativeObjI, force_depends, commands, false); } @@ -799,11 +796,10 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( vars.AssemblySource = shellObjS.c_str(); // Expand placeholders in the commands. - for (std::vector::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( @@ -817,7 +813,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( commands.push_back(cmd); } - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, relativeObjS, force_depends, commands, false); } @@ -829,7 +825,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( objectRequires += ".requires"; std::vector p_depends; // always provide an empty requires target - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, objectRequires, p_depends, no_commands, true); @@ -847,14 +843,14 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( p_depends.clear(); p_depends.push_back(objectRequires); - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 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, + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, temp, p_depends, no_commands, false); } @@ -871,16 +867,15 @@ void cmMakefileTargetGenerator::WriteTargetRequiresRules() // This target drives dependency generation for all object files. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath(); std::string objTarget; - for (std::vector::const_iterator obj = this->Objects.begin(); - obj != this->Objects.end(); ++obj) { + for (std::string const& obj : this->Objects) { objTarget = relPath; - objTarget += *obj; + objTarget += obj; objTarget += ".requires"; depends.push_back(objTarget); } // Write the rule. - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr, depTarget, depends, no_commands, true); } @@ -902,7 +897,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); } @@ -959,7 +954,7 @@ 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, *o, output_depends, output_commands, o_symbolic, in_help); if (!o_symbolic) { @@ -998,12 +993,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 +1010,8 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() << "set(CMAKE_TARGET_LINKED_INFO_FILES\n"; /* clang-format on */ std::vector dirs = this->GetLinkedTargetDirectories(); - for (std::vector::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"; } @@ -1106,7 +1098,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,9 +1109,8 @@ void cmMakefileTargetGenerator::DriveCustomCommands( std::vector sources; this->GeneratorTarget->GetSourceFiles( sources, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); - for (std::vector::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& outputs = ccg.GetOutputs(); @@ -1169,8 +1160,8 @@ void cmMakefileTargetGenerator::GenerateCustomRuleFile( // Write the rule. const std::vector& 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,12 +1169,10 @@ 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, + std::string srcFullPath = cmSystemTools::CollapseFullPath(idi.second); + this->LocalGenerator->AddImplicitDepends(this->GeneratorTarget, idi.first, objFullPath.c_str(), srcFullPath.c_str()); } @@ -1216,11 +1205,10 @@ void cmMakefileTargetGenerator::WriteObjectsVariable( if (!lineContinue) { lineContinue = "\\"; } - for (std::vector::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); + obj.c_str(), useWatcomQuote); } *this->BuildFileStream << "\n"; @@ -1237,14 +1225,12 @@ void cmMakefileTargetGenerator::WriteObjectsVariable( /* clang-format on */ std::string currentBinDir = this->LocalGenerator->GetCurrentBinaryDirectory(); - for (std::vector::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); + obj.c_str(), useWatcomQuote); } *this->BuildFileStream << "\n" << "\n"; @@ -1275,7 +1261,7 @@ public: (this->CurrentString.length() + 1 + this->NextObject.length() > this->LengthLimit)) { this->Strings.push_back(this->CurrentString); - this->CurrentString = ""; + this->CurrentString.clear(); this->Space = ""; } @@ -1314,14 +1300,11 @@ void cmMakefileTargetGenerator::WriteObjectsStrings( cmMakefileTargetGeneratorObjectStrings helper( objStrings, this->LocalGenerator, this->LocalGenerator->GetStateSnapshot().GetDirectory(), limit); - for (std::vector::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::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 +1324,7 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule( std::vector 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."; @@ -1389,10 +1372,9 @@ void cmMakefileTargetGenerator::AppendObjectDepends( // Add dependencies on the compiled object files. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath(); std::string objTarget; - for (std::vector::const_iterator obj = this->Objects.begin(); - obj != this->Objects.end(); ++obj) { + for (std::string const& obj : this->Objects) { objTarget = relPath; - objTarget += *obj; + objTarget += obj; depends.push_back(objTarget); } @@ -1417,19 +1399,16 @@ void cmMakefileTargetGenerator::AppendLinkDepends( if (cmGeneratorTarget::ModuleDefinitionInfo const* mdi = this->GeneratorTarget->GetModuleDefinitionInfo( this->GetConfigName())) { - for (std::vector::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 manifest_srcs; this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName); - for (std::vector::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. @@ -1472,12 +1451,11 @@ void cmMakefileTargetGenerator::CreateLinkScript( linkScriptName += name; cmGeneratedFileStream linkScriptStream(linkScriptName.c_str()); linkScriptStream.SetCopyIfDifferent(true); - for (std::vector::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"; } } @@ -1512,14 +1490,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::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::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 @@ -1742,22 +1717,17 @@ void cmMakefileTargetGenerator::GenDefFile( cmGeneratedFileStream fout(objlist_file.c_str()); if (mdi->WindowsExportAllSymbols) { - for (std::vector::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::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::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..5ab7e36b0 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 #include @@ -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); @@ -81,8 +81,7 @@ protected: { } - void operator()(cmSourceFile const& source, - const char* pkgloc) CM_OVERRIDE; + void operator()(cmSourceFile const& source, const char* pkgloc) override; private: cmMakefileTargetGenerator* Generator; @@ -168,8 +167,7 @@ protected: /** Add commands for generate def files */ void GenDefFile(std::vector& 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; diff --git a/Source/cmMakefileUtilityTargetGenerator.cxx b/Source/cmMakefileUtilityTargetGenerator.cxx index a7c5d27f2..46df0d89c 100644 --- a/Source/cmMakefileUtilityTargetGenerator.cxx +++ b/Source/cmMakefileUtilityTargetGenerator.cxx @@ -95,7 +95,7 @@ void cmMakefileUtilityTargetGenerator::WriteRuleFiles() } // 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 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; protected: bool HandleExprCommand(std::vector const& args); 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmNinjaLinkLineComputer.h b/Source/cmNinjaLinkLineComputer.h index 13f05a838..0ed53f45a 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 @@ -23,8 +23,7 @@ public: cmStateDirectory const& stateDir, cmGlobalNinjaGenerator const* gg); - std::string ConvertToLinkReference(std::string const& input) const - CM_OVERRIDE; + 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..e0cc35a15 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -6,11 +6,11 @@ #include #include #include +#include // IWYU pragma: keep #include #include #include "cmAlgorithms.h" -#include "cmCustomCommand.h" #include "cmCustomCommandGenerator.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" @@ -30,9 +30,10 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" +class cmCustomCommand; + cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator( cmGeneratorTarget* target) : cmNinjaTargetGenerator(target) @@ -112,17 +113,14 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules() std::vector sourceFiles; this->GetGeneratorTarget()->GetObjectSources( sourceFiles, this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE")); - for (std::vector::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::const_iterator l = languages.begin(); - l != languages.end(); ++l) { - this->WriteLanguageRules(*l); + for (std::string const& language : languages) { + this->WriteLanguageRules(language); } } @@ -142,7 +140,7 @@ const char* cmNinjaNormalTargetGenerator::GetVisibleTypeName() const case cmStateEnums::EXECUTABLE: return "executable"; default: - return CM_NULLPTR; + return nullptr; } } @@ -243,16 +241,15 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile) launcher += " "; } - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->GetLocalGenerator()->CreateRulePlaceholderExpander()); // Rule for linking library/executable. std::vector linkCmds = this->ComputeDeviceLinkCmd(); - for (std::vector::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. @@ -368,16 +365,15 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) launcher += " "; } - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->GetLocalGenerator()->CreateRulePlaceholderExpander()); // Rule for linking library/executable. std::vector linkCmds = this->ComputeLinkCmd(); - for (std::vector::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. @@ -409,10 +405,14 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) this->GetLocalGenerator()->ConvertToOutputFormat( cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL); if (targetType == cmStateEnums::EXECUTABLE) { + std::vector commandLines; + commandLines.push_back(cmakeCommand + + " -E cmake_symlink_executable $in $out"); + commandLines.push_back("$POST_BUILD"); + this->GetGlobalGenerator()->AddRule( "CMAKE_SYMLINK_EXECUTABLE", - cmakeCommand + " -E cmake_symlink_executable" - " $in $out && $POST_BUILD", + this->GetLocalGenerator()->BuildCommandLine(commandLines), "Creating executable symlink $out", "Rule for creating " "executable symlink.", /*depfile*/ "", @@ -422,10 +422,14 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile) /*restat*/ "", /*generator*/ false); } else { + std::vector commandLines; + commandLines.push_back(cmakeCommand + + " -E cmake_symlink_library $in $SONAME $out"); + commandLines.push_back("$POST_BUILD"); + this->GetGlobalGenerator()->AddRule( "CMAKE_SYMLINK_LIBRARY", - cmakeCommand + " -E cmake_symlink_library" - " $in $SONAME $out && $POST_BUILD", + this->GetLocalGenerator()->BuildCommandLine(commandLines), "Creating library symlink $out", "Rule for creating " "library symlink.", /*depfile*/ "", @@ -477,12 +481,21 @@ std::vector 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()) { + 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)); @@ -623,7 +636,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement() vars["TARGET_FILE"] = localGen.ConvertToOutputFormat(targetOutputReal, cmOutputConverter::SHELL); - CM_AUTO_PTR linkLineComputer( + std::unique_ptr linkLineComputer( new cmNinjaLinkLineDeviceComputer( this->GetLocalGenerator(), this->GetLocalGenerator()->GetStateSnapshot().GetDirectory(), @@ -654,7 +667,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement() std::string t = vars["ARCH_FLAGS"]; localGen.AddArchitectureFlags(t, &genTarget, cudaLinkLanguage, cfgName); vars["ARCH_FLAGS"] = t; - t = ""; + t.clear(); localGen.AddLanguageFlagsForLinking(t, &genTarget, cudaLinkLanguage, cfgName); vars["LANGUAGE_COMPILE_FLAGS"] = t; @@ -714,10 +727,8 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement() &postBuildCmdLines }; for (unsigned i = 0; i != 3; ++i) { - for (std::vector::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 const& ccByproducts = ccg.GetByproducts(); std::transform(ccByproducts.begin(), ccByproducts.end(), @@ -828,7 +839,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() vars["TARGET_FILE"] = localGen.ConvertToOutputFormat(targetOutputReal, cmOutputConverter::SHELL); - CM_AUTO_PTR linkLineComputer( + std::unique_ptr linkLineComputer( this->GetGlobalGenerator()->CreateLinkLineComputer( this->GetLocalGenerator(), this->GetLocalGenerator()->GetStateSnapshot().GetDirectory())); @@ -873,7 +884,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() std::string t = vars["ARCH_FLAGS"]; localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName); vars["ARCH_FLAGS"] = t; - t = ""; + t.clear(); t += lwyuFlags; localGen.AddLanguageFlagsForLinking(t, &genTarget, TargetLinkLanguage, cfgName); @@ -943,10 +954,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() &postBuildCmdLines }; for (unsigned i = 0; i != 3; ++i) { - for (std::vector::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 const& ccByproducts = ccg.GetByproducts(); std::transform(ccByproducts.begin(), ccByproducts.end(), @@ -976,17 +985,15 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() 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::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 @@ -1033,11 +1040,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() // 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) { + this->GetGlobalGenerator()->SeenCustomCommandOutput(o); + outputs.push_back(o); } // Write the build statement for this target. @@ -1065,7 +1070,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() if (targetOutputReal == soName || targetOutput == soName) { symlinkVars["SONAME"] = soName; } else { - symlinkVars["SONAME"] = ""; + symlinkVars["SONAME"].clear(); symlinks.push_back(soName); } symlinks.push_back(targetOutput); diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h index 677b1c666..01cc8816e 100644 --- a/Source/cmNinjaNormalTargetGenerator.h +++ b/Source/cmNinjaNormalTargetGenerator.h @@ -3,7 +3,7 @@ #ifndef cmNinjaNormalTargetGenerator_h #define cmNinjaNormalTargetGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmNinjaTargetGenerator.h" @@ -16,9 +16,9 @@ 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; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index d38dbcb09..5805259a5 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -8,6 +8,7 @@ #include #include #include +#include // IWYU pragma: keep #include #include @@ -29,7 +30,6 @@ #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" cmNinjaTargetGenerator* cmNinjaTargetGenerator::New(cmGeneratorTarget* target) @@ -47,14 +47,14 @@ cmNinjaTargetGenerator* cmNinjaTargetGenerator::New(cmGeneratorTarget* target) return new cmNinjaUtilityTargetGenerator(target); default: - return CM_NULLPTR; + return nullptr; } } cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target) : cmCommonTargetGenerator(target) - , MacOSXContentGenerator(CM_NULLPTR) - , OSXBundleGenerator(CM_NULLPTR) + , MacOSXContentGenerator(nullptr) + , OSXBundleGenerator(nullptr) , MacContentFolders() , LocalGenerator( static_cast(target->GetLocalGenerator())) @@ -138,7 +138,7 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject( if (const char* cflags = source->GetProperty("COMPILE_FLAGS")) { std::string config = this->LocalGenerator->GetConfigName(); cmGeneratorExpression ge; - CM_AUTO_PTR cge = ge.Parse(cflags); + std::unique_ptr cge = ge.Parse(cflags); const char* evaluatedFlags = cge->Evaluate(this->LocalGenerator, config, false, this->GeneratorTarget); this->LocalGenerator->AppendFlags(flags, evaluatedFlags); @@ -215,19 +215,16 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const if (cmGeneratorTarget::ModuleDefinitionInfo const* mdi = this->GeneratorTarget->GetModuleDefinitionInfo( this->GetConfigName())) { - for (std::vector::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 manifest_srcs; this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName); - for (std::vector::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. @@ -428,7 +425,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) // The explicit preprocessing step will handle dependency scanning. } else if (this->NeedDepTypeMSVC(lang)) { deptype = "msvc"; - depfile = ""; + depfile.clear(); flags += " /showIncludes"; } else if (mf->IsOn("CMAKE_NINJA_CMCLDEPS_" + lang)) { // For the MS resource compiler we need cmcldeps, but skip dependencies @@ -441,7 +438,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) : mf->GetSafeDefinition("CMAKE_CXX_COMPILER"); cldeps = "\""; cldeps += cmSystemTools::GetCMClDepsCommand(); - cldeps += "\" " + lang + " " + vars.Source + " \"$DEP_FILE\" $out \""; + cldeps += "\" " + lang + " " + vars.Source + " $DEP_FILE $out \""; cldeps += mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"); cldeps += "\" \"" + cl + "\" "; } @@ -466,7 +463,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) vars.Flags = flags.c_str(); vars.DependencyFile = depfile.c_str(); - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->GetLocalGenerator()->CreateRulePlaceholderExpander()); std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat( @@ -519,11 +516,10 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) std::vector ppCmds; cmSystemTools::ExpandListArgument(ppCmd, ppCmds); - for (std::vector::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. @@ -557,17 +553,11 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) // Write the rule for ninja dyndep file generation. std::vector ddCmds; -#ifdef _WIN32 - // Windows command line length is limited -> use response file for dyndep - // rules + // Command line length is almost always 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 // Run CMake dependency scanner on preprocessed output. std::string const cmake = this->GetLocalGenerator()->ConvertToOutputFormat( @@ -623,10 +613,13 @@ 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 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 = this->GetLocalGenerator()->ConvertToOutputFormat( cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL); - run_iwyu += " -E __run_iwyu"; + run_iwyu += " -E __run_co_compile"; if (iwyu && *iwyu) { run_iwyu += " --iwyu="; run_iwyu += this->GetLocalGenerator()->EscapeForShell(iwyu); @@ -639,7 +632,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 += " -- "; @@ -648,16 +646,15 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) } // Maybe insert a compiler launcher like ccache or distcc - if (!compileCmds.empty() && (lang == "C" || lang == "CXX")) { + if (!compileCmds.empty() && + (lang == "C" || lang == "CXX" || lang == "CUDA")) { std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER"; const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop); if (clauncher && *clauncher) { std::vector launcher_cmd; cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true); - for (std::vector::iterator i = launcher_cmd.begin(), - e = launcher_cmd.end(); - i != e; ++i) { - *i = this->LocalGenerator->EscapeForShell(*i); + for (std::string& i : launcher_cmd) { + i = this->LocalGenerator->EscapeForShell(i); } std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " "; compileCmds.front().insert(0, run_launcher); @@ -668,10 +665,9 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) compileCmds.front().insert(0, cldeps); } - for (std::vector::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); } @@ -702,10 +698,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); std::vector customCommands; this->GeneratorTarget->GetCustomCommands(customCommands, config); - for (std::vector::const_iterator si = - customCommands.begin(); - si != customCommands.end(); ++si) { - cmCustomCommand const* cc = (*si)->GetCustomCommand(); + 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 @@ -722,10 +716,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() extraSources, this->MacOSXContentGenerator); std::vector externalObjects; this->GeneratorTarget->GetExternalObjects(externalObjects, config); - for (std::vector::const_iterator si = - externalObjects.begin(); - si != externalObjects.end(); ++si) { - this->Objects.push_back(this->GetSourceFilePath(*si)); + for (cmSourceFile const* sf : externalObjects) { + this->Objects.push_back(this->GetSourceFilePath(sf)); } cmNinjaDeps orderOnlyDeps; @@ -737,10 +729,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() this->ExtraFiles.end()); // Add order-only dependencies on custom command outputs. - for (std::vector::const_iterator cci = - this->CustomCommands.begin(); - cci != this->CustomCommands.end(); ++cci) { - cmCustomCommand const* cc = *cci; + for (cmCustomCommand const* cc : this->CustomCommands) { cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this->GetLocalGenerator()); const std::vector& ccoutputs = ccg.GetOutputs(); @@ -765,10 +754,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements() } std::vector objectSources; this->GeneratorTarget->GetObjectSources(objectSources, config); - for (std::vector::const_iterator si = - objectSources.begin(); - si != objectSources.end(); ++si) { - this->WriteObjectBuildStatement(*si); + for (cmSourceFile const* sf : objectSources) { + this->WriteObjectBuildStatement(sf); } if (!this->DDIFiles.empty()) { @@ -845,10 +832,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( if (const char* objectDeps = source->GetProperty("OBJECT_DEPENDS")) { std::vector depList; cmSystemTools::ExpandListArgument(objectDeps, depList); - for (std::vector::iterator odi = depList.begin(); - odi != depList.end(); ++odi) { - if (cmSystemTools::FileIsFullPath(*odi)) { - *odi = cmSystemTools::CollapseFullPath(*odi); + for (std::string& odi : depList) { + if (cmSystemTools::FileIsFullPath(odi)) { + odi = cmSystemTools::CollapseFullPath(odi); } } std::transform(depList.begin(), depList.end(), @@ -896,9 +882,15 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( // The actual compilation will now use the preprocessed source. explicitDeps.push_back(ppFileName); - // Preprocessing and compilation use the same flags. + // Preprocessing and compilation generally use the same flags. ppVars["FLAGS"] = vars["FLAGS"]; + // In case compilation requires flags that are incompatible with + // preprocessing, include them here. + std::string const postFlag = + this->Makefile->GetSafeDefinition("CMAKE_Fortran_POSTPROCESS_FLAG"); + this->LocalGenerator->AppendFlags(vars["FLAGS"], postFlag); + // Move preprocessor definitions to the preprocessor build statement. std::swap(ppVars["DEFINES"], vars["DEFINES"]); @@ -1010,19 +1002,17 @@ void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang) std::vector includes; this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget, lang, this->GetConfigName()); - for (std::vector::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 linked = this->GetLinkedTargetDirectories(); - for (std::vector::iterator i = linked.begin(); - i != linked.end(); ++i) { - tdi_linked_target_dirs.append(*i); + for (std::string const& l : linked) { + tdi_linked_target_dirs.append(l); } std::string const tdin = this->GetTargetDependInfoPath(lang); @@ -1087,13 +1077,12 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand( cmSystemTools::ExpandListArgument(compileCmd, compileCmds); } - CM_AUTO_PTR rulePlaceholderExpander( + std::unique_ptr rulePlaceholderExpander( this->GetLocalGenerator()->CreateRulePlaceholderExpander()); - for (std::vector::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); } diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 5eb7a9a49..770a99d7f 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -3,7 +3,7 @@ #ifndef cmNinjaTargetGenerator_h #define cmNinjaTargetGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCommonTargetGenerator.h" #include "cmGlobalNinjaGenerator.h" @@ -31,7 +31,7 @@ public: cmNinjaTargetGenerator(cmGeneratorTarget* target); /// Destructor. - ~cmNinjaTargetGenerator() CM_OVERRIDE; + ~cmNinjaTargetGenerator() override; virtual void Generate() = 0; @@ -77,8 +77,7 @@ 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); @@ -142,8 +141,7 @@ protected: { } - void operator()(cmSourceFile const& source, - const char* pkgloc) CM_OVERRIDE; + void operator()(cmSourceFile const& source, const char* pkgloc) override; private: cmNinjaTargetGenerator* Generator; diff --git a/Source/cmNinjaTypes.h b/Source/cmNinjaTypes.h index ec435d9dd..9e962f135 100644 --- a/Source/cmNinjaTypes.h +++ b/Source/cmNinjaTypes.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include #include #include @@ -16,6 +17,7 @@ enum cmNinjaTargetDepends }; typedef std::vector cmNinjaDeps; +typedef std::set cmNinjaOuts; typedef std::map cmNinjaVars; #endif // ! cmNinjaTypes_h diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx index 500ff4a45..7adeb8e2b 100644 --- a/Source/cmNinjaUtilityTargetGenerator.cxx +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -51,17 +51,15 @@ void cmNinjaUtilityTargetGenerator::Generate() bool uses_terminal = false; for (unsigned i = 0; i != 2; ++i) { - for (std::vector::const_iterator ci = - cmdLists[i]->begin(); - ci != cmdLists[i]->end(); ++ci) { - cmCustomCommandGenerator ccg(*ci, this->GetConfigName(), + for (cmCustomCommand const& ci : *cmdLists[i]) { + cmCustomCommandGenerator ccg(ci, this->GetConfigName(), this->GetLocalGenerator()); this->GetLocalGenerator()->AppendCustomCommandDeps(ccg, deps); this->GetLocalGenerator()->AppendCustomCommandLines(ccg, commands); std::vector const& ccByproducts = ccg.GetByproducts(); std::transform(ccByproducts.begin(), ccByproducts.end(), std::back_inserter(util_outputs), MapToNinjaPath()); - if (ci->GetUsesTerminal()) { + if (ci.GetUsesTerminal()) { uses_terminal = true; } } @@ -71,9 +69,8 @@ void cmNinjaUtilityTargetGenerator::Generate() std::string config = this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"); this->GetGeneratorTarget()->GetSourceFiles(sources, config); - for (std::vector::const_iterator source = sources.begin(); - source != sources.end(); ++source) { - if (cmCustomCommand* cc = (*source)->GetCustomCommand()) { + for (cmSourceFile const* source : sources) { + if (cmCustomCommand const* cc = source->GetCustomCommand()) { cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this->GetLocalGenerator()); this->GetLocalGenerator()->AddCustomCommandTarget( @@ -132,10 +129,8 @@ void cmNinjaUtilityTargetGenerator::Generate() 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) { + this->GetGlobalGenerator()->SeenCustomCommandOutput(util_output); } this->GetGlobalGenerator()->WriteCustomCommandBuild( 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..c85c82d84 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" @@ -21,7 +19,7 @@ cmOSXBundleGenerator::cmOSXBundleGenerator(cmGeneratorTarget* target, , Makefile(target->Target->GetMakefile()) , LocalGenerator(target->GetLocalGenerator()) , ConfigName(configName) - , MacContentFolders(CM_NULLPTR) + , MacContentFolders(nullptr) { if (this->MustSkip()) { return; @@ -197,12 +195,11 @@ void cmOSXBundleGenerator::GenerateMacOSXContentStatements( return; } - for (std::vector::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); } } } 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmOrderDirectories.cxx b/Source/cmOrderDirectories.cxx index 333e3134c..27ad71037 100644 --- a/Source/cmOrderDirectories.cxx +++ b/Source/cmOrderDirectories.cxx @@ -75,9 +75,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) && @@ -150,7 +149,7 @@ public: } } - void Report(std::ostream& e) CM_OVERRIDE + void Report(std::ostream& e) override { e << "runtime library ["; if (this->SOName.empty()) { @@ -161,7 +160,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. @@ -205,12 +204,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 +225,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::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; } @@ -346,9 +343,8 @@ void cmOrderDirectories::SetImplicitDirectories( std::set const& implicitDirs) { this->ImplicitDirectories.clear(); - for (std::set::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 +371,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 +396,19 @@ int cmOrderDirectories::AddOriginalDirectory(std::string const& dir) void cmOrderDirectories::AddOriginalDirectories( std::vector const& dirs) { - for (std::vector::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 +437,15 @@ void cmOrderDirectories::FindConflicts() } // Clean up the conflict graph representation. - for (std::vector::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 +457,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; } @@ -515,8 +509,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,10 +536,9 @@ 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"; } } diff --git a/Source/cmOrderDirectories.h b/Source/cmOrderDirectories.h index 3a0637afb..5916f7ab4 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 @@ -26,7 +26,7 @@ public: const char* purpose); ~cmOrderDirectories(); 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 const& extra); void AddLanguageDirectories(std::vector const& dirs); diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index 14c986dd8..dac656912 100644 --- a/Source/cmOutputConverter.cxx +++ b/Source/cmOutputConverter.cxx @@ -285,12 +285,11 @@ cmOutputConverter::FortranFormat cmOutputConverter::GetFortranFormat( if (value && *value) { std::vector fmt; cmSystemTools::ExpandListArgument(value, fmt); - for (std::vector::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; } } @@ -389,7 +388,7 @@ int cmOutputConverter::Shell__CharNeedsQuotes(char c, int flags) int cmOutputConverter::Shell__CharIsMakeVariableName(char c) { - return c && (c == '_' || isalpha(((int)c))); + return c && (c == '_' || isalpha((static_cast(c)))); } const char* cmOutputConverter::Shell__SkipMakeVariables(const char* c) diff --git a/Source/cmOutputRequiredFilesCommand.cxx b/Source/cmOutputRequiredFilesCommand.cxx index 2339d6876..cde90375f 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; @@ -31,7 +30,7 @@ public: */ cmDependInformation() : DependDone(false) - , SourceFile(CM_NULLPTR) + , SourceFile(nullptr) { } @@ -114,8 +113,9 @@ public: std::set uniqueIncludes; std::vector 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 : targets) { + const char* incDirProp = + target.second.GetProperty("INCLUDE_DIRECTORIES"); if (!incDirProp) { continue; } @@ -126,9 +126,7 @@ public: std::vector includes; cmSystemTools::ExpandListArgument(incDirs, includes); - for (std::vector::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 +134,8 @@ public: } } - for (std::vector::const_iterator it = - orderedAndUniqueIncludes.begin(); - it != orderedAndUniqueIncludes.end(); ++it) { - this->AddSearchPath(*it); + for (std::string const& inc : orderedAndUniqueIncludes) { + this->AddSearchPath(inc); } } @@ -157,7 +153,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; } @@ -202,7 +198,7 @@ protected: message += includeFile; message += " for file "; message += info->FullPath; - cmSystemTools::Error(message.c_str(), CM_NULLPTR); + cmSystemTools::Error(message.c_str(), nullptr); } continue; } @@ -220,10 +216,7 @@ protected: if (cmSystemTools::FileExists(cxxFile.c_str())) { found = true; } - for (std::vector::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())) { @@ -235,10 +228,7 @@ protected: if (cmSystemTools::FileExists(cxxFile.c_str())) { found = true; } - for (std::vector::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())) { @@ -251,10 +241,7 @@ protected: if (cmSystemTools::FileExists(cxxFile.c_str())) { found = true; } - for (std::vector::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())) { @@ -267,10 +254,7 @@ protected: if (cmSystemTools::FileExists(cxxFile.c_str())) { found = true; } - for (std::vector::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())) { @@ -328,7 +312,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 +321,8 @@ protected: if (!cFile.GetDepends().empty()) { // Dependency hints have been given. Use them to begin the // recursion. - for (std::vector::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,10 +339,7 @@ protected: found = true; } else { // try to guess which include path to use - for (std::vector::iterator t = - this->IncludeDirectories.begin(); - t != this->IncludeDirectories.end(); ++t) { - std::string incpath = *t; + for (std::string incpath : this->IncludeDirectories) { if (!incpath.empty() && incpath[incpath.size() - 1] != '/') { incpath = incpath + "/"; } @@ -383,7 +362,7 @@ protected: } else { // Destroy the name of the file so that it won't be output as a // dependency. - info->FullPath = ""; + info->FullPath.clear(); } } } @@ -442,10 +421,7 @@ protected: return fp; } - for (std::vector::iterator i = - this->IncludeDirectories.begin(); - i != this->IncludeDirectories.end(); ++i) { - std::string path = *i; + for (std::string path : this->IncludeDirectories) { if (!path.empty() && path[path.size() - 1] != '/') { path = path + "/"; } @@ -532,19 +508,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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; void ListDependencies(cmDependInformation const* info, FILE* fout, std::set* visited); diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx index d75ee8e86..0922e6e24 100644 --- a/Source/cmParseArgumentsCommand.cxx +++ b/Source/cmParseArgumentsCommand.cxx @@ -5,7 +5,6 @@ #include #include #include -#include #include #include "cmAlgorithms.h" @@ -19,11 +18,11 @@ static std::string escape_arg(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; } @@ -70,7 +69,7 @@ bool cmParseArgumentsCommand::InitialPass(std::vector const& args, // options, single values and multi values typedef std::map options_map; typedef std::map single_map; - typedef std::map > multi_map; + typedef std::map> multi_map; options_map options; single_map single; multi_map multi; @@ -85,37 +84,31 @@ bool cmParseArgumentsCommand::InitialPass(std::vector const& args, // the second argument is a (cmake) list of options without argument std::vector list; cmSystemTools::ExpandListArgument(*argIter++, list); - for (std::vector::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); + for (std::string const& iter : list) { + if (!used_keywords.insert(iter).second) { + this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + iter); } - options[*iter]; // default initialize + options[iter]; // default initialize } // the third argument is a (cmake) list of single argument options list.clear(); cmSystemTools::ExpandListArgument(*argIter++, list); - for (std::vector::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); + for (std::string const& iter : list) { + if (!used_keywords.insert(iter).second) { + this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + iter); } - single[*iter]; // default initialize + single[iter]; // default initialize } // the fourth argument is a (cmake) list of multi argument options list.clear(); cmSystemTools::ExpandListArgument(*argIter++, list); - for (std::vector::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); + for (std::string const& iter : list) { + if (!used_keywords.insert(iter).second) { + this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + iter); } - multi[*iter]; // default initialize + multi[iter]; // default initialize } enum insideValues @@ -160,46 +153,45 @@ bool cmParseArgumentsCommand::InitialPass(std::vector const& args, } // 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); + for (std::string const& arg : list) { + const options_map::iterator optIter = options.find(arg); if (optIter != options.end()) { insideValues = NONE; optIter->second = true; continue; } - const single_map::iterator singleIter = single.find(*argIter); + const single_map::iterator singleIter = single.find(arg); if (singleIter != single.end()) { insideValues = SINGLE; - currentArgName = *argIter; + currentArgName = arg; continue; } - const multi_map::iterator multiIter = multi.find(*argIter); + const multi_map::iterator multiIter = multi.find(arg); if (multiIter != multi.end()) { insideValues = MULTI; - currentArgName = *argIter; + currentArgName = arg; continue; } switch (insideValues) { case SINGLE: - single[currentArgName] = *argIter; + single[currentArgName] = arg; insideValues = NONE; break; case MULTI: if (parseFromArgV) { - multi[currentArgName].push_back(escape_arg(*argIter)); + multi[currentArgName].push_back(escape_arg(arg)); } else { - multi[currentArgName].push_back(*argIter); + multi[currentArgName].push_back(arg); } break; default: if (parseFromArgV) { - unparsed.push_back(escape_arg(*argIter)); + unparsed.push_back(escape_arg(arg)); } else { - unparsed.push_back(*argIter); + unparsed.push_back(arg); } break; } @@ -208,28 +200,24 @@ bool cmParseArgumentsCommand::InitialPass(std::vector const& args, // now iterate over the collected values and update their definition // within the current scope. undefine if necessary. - for (options_map::const_iterator iter = options.begin(), end = options.end(); - iter != end; ++iter) { - this->Makefile->AddDefinition(prefix + iter->first, - iter->second ? "TRUE" : "FALSE"); + for (auto const& iter : options) { + 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()); + for (auto const& iter : single) { + if (!iter.second.empty()) { + this->Makefile->AddDefinition(prefix + iter.first, iter.second.c_str()); } else { - this->Makefile->RemoveDefinition(prefix + iter->first); + this->Makefile->RemoveDefinition(prefix + iter.first); } } - for (multi_map::const_iterator iter = multi.begin(), end = multi.end(); - iter != end; ++iter) { - if (!iter->second.empty()) { + for (auto const& iter : multi) { + if (!iter.second.empty()) { this->Makefile->AddDefinition( - prefix + iter->first, cmJoin(cmMakeRange(iter->second), ";").c_str()); + prefix + iter.first, cmJoin(cmMakeRange(iter.second), ";").c_str()); } else { - this->Makefile->RemoveDefinition(prefix + iter->first); + this->Makefile->RemoveDefinition(prefix + iter.first); } } 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmPathLabel.cxx b/Source/cmPathLabel.cxx index 30ba08151..4793206f9 100644 --- a/Source/cmPathLabel.cxx +++ b/Source/cmPathLabel.cxx @@ -2,15 +2,13 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmPathLabel.h" -#include - cmPathLabel::cmPathLabel(const std::string& label) : Label(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/cmPipeConnection.cxx b/Source/cmPipeConnection.cxx new file mode 100644 index 000000000..9e565f60a --- /dev/null +++ b/Source/cmPipeConnection.cxx @@ -0,0 +1,82 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmPipeConnection.h" + +#include "cmServer.h" + +cmPipeConnection::cmPipeConnection(const std::string& name, + cmConnectionBufferStrategy* bufferStrategy) + : cmEventBasedConnection(bufferStrategy) + , PipeName(name) +{ +} + +void cmPipeConnection::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->Server->GetLoop(), rejectPipe, 0); + uv_accept(server, reinterpret_cast(rejectPipe)); + uv_close(reinterpret_cast(rejectPipe), + &on_close_delete); + return; + } + + this->ClientPipe = new uv_pipe_t(); + uv_pipe_init(this->Server->GetLoop(), this->ClientPipe, 0); + this->ClientPipe->data = static_cast(this); + auto client = reinterpret_cast(this->ClientPipe); + if (uv_accept(server, client) != 0) { + uv_close(reinterpret_cast(client), + &on_close_delete); + this->ClientPipe = nullptr; + return; + } + this->ReadStream = client; + this->WriteStream = client; + + uv_read_start(this->ReadStream, on_alloc_buffer, on_read); + Server->OnConnected(this); +} + +bool cmPipeConnection::OnServeStart(std::string* errorMessage) +{ + this->ServerPipe = new uv_pipe_t(); + uv_pipe_init(this->Server->GetLoop(), this->ServerPipe, 0); + this->ServerPipe->data = static_cast(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(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 cmConnection::OnServeStart(errorMessage); +} + +bool cmPipeConnection::OnConnectionShuttingDown() +{ + if (this->ClientPipe) { + uv_close(reinterpret_cast(this->ClientPipe), + &on_close_delete); + this->WriteStream->data = nullptr; + } + uv_close(reinterpret_cast(this->ServerPipe), + &on_close_delete); + + this->ClientPipe = nullptr; + this->ServerPipe = nullptr; + this->WriteStream = nullptr; + this->ReadStream = nullptr; + + return cmEventBasedConnection::OnConnectionShuttingDown(); +} diff --git a/Source/cmPipeConnection.h b/Source/cmPipeConnection.h new file mode 100644 index 000000000..7b8984296 --- /dev/null +++ b/Source/cmPipeConnection.h @@ -0,0 +1,28 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include "cmConfigure.h" // IWYU pragma: keep + +#include + +#include "cmConnection.h" +#include "cm_uv.h" + +class cmPipeConnection : public cmEventBasedConnection +{ +public: + cmPipeConnection(const std::string& name, + cmConnectionBufferStrategy* bufferStrategy = nullptr); + + bool OnServeStart(std::string* pString) override; + + bool OnConnectionShuttingDown() 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/cmPolicies.cxx b/Source/cmPolicies.cxx index da3edd427..e7d1b7218 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -8,7 +8,6 @@ #include "cmVersion.h" #include "cmake.h" -#include "cmConfigure.h" #include #include #include @@ -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,9 +120,8 @@ 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::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. " @@ -142,7 +140,7 @@ static bool GetPolicyDefault(cmMakefile* mf, std::string const& policy, *defaultSetting = cmPolicies::NEW; } else if (defaultValue == "OLD") { *defaultSetting = cmPolicies::OLD; - } else if (defaultValue == "") { + } else if (defaultValue.empty()) { *defaultSetting = cmPolicies::WARN; } else { std::ostringstream e; diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 69cbc1844..6c33e2b0f 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, \ @@ -206,7 +206,12 @@ 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) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Source/cmProcessTools.cxx b/Source/cmProcessTools.cxx index de7b06126..7ab1fa3fc 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), p)) { 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,15 +38,15 @@ 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) + : Log(nullptr) + , Prefix(nullptr) , Separator(sep) , LineEnd('\0') , IgnoreCR(ignoreCR) @@ -73,11 +73,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..23fa74e85 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 @@ -59,7 +59,7 @@ public: char Separator; char LineEnd; 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 +70,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..fea8a9dde 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -195,15 +195,14 @@ bool cmProjectCommand::InitialPass(std::vector const& args, vv.push_back(projectName + "_VERSION_PATCH"); vv.push_back(projectName + "_VERSION_TWEAK"); std::string vw; - for (std::vector::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; + vw += i; } else { - this->Makefile->AddDefinition(*i, ""); + this->Makefile->AddDefinition(i, ""); } } } diff --git a/Source/cmProjectCommand.h b/Source/cmProjectCommand.h index 3c579ac9d..80fa235e2 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 #include @@ -26,14 +26,14 @@ 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #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 #include #include @@ -22,9 +21,8 @@ cmProperty* cmPropertyMap::GetOrCreateProperty(const std::string& name) std::vector cmPropertyMap::GetPropertyList() const { std::vector 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..ae1fdfae2 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -78,7 +78,7 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector const& args, 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx index d3c663176..3d586d6bd 100644 --- a/Source/cmQTWrapUICommand.cxx +++ b/Source/cmQTWrapUICommand.cxx @@ -109,8 +109,8 @@ bool cmQTWrapUICommand::InitialPass(std::vector const& args, std::vector 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmQtAutoGen.cxx b/Source/cmQtAutoGen.cxx new file mode 100644 index 000000000..5e89978b9 --- /dev/null +++ b/Source/cmQtAutoGen.cxx @@ -0,0 +1,374 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmQtAutoGen.h" +#include "cmAlgorithms.h" +#include "cmProcessOutput.h" +#include "cmSystemTools.h" + +#include "cmsys/FStream.hxx" +#include "cmsys/RegularExpression.hxx" + +#include +#include +#include + +// - Static variables + +std::string const genNameGen = "AutoGen"; +std::string const genNameMoc = "AutoMoc"; +std::string const genNameUic = "AutoUic"; +std::string const genNameRcc = "AutoRcc"; + +std::string const mcNameSingle = "SINGLE"; +std::string const mcNameWrap = "WRAP"; +std::string const mcNameFull = "FULL"; + +// - Static functions + +/// @brief Merges newOpts into baseOpts +/// @arg valueOpts list of options that accept a value +void MergeOptions(std::vector& baseOpts, + std::vector const& newOpts, + std::vector const& valueOpts, bool isQt5) +{ + typedef std::vector::iterator Iter; + typedef std::vector::const_iterator CIter; + if (newOpts.empty()) { + return; + } + if (baseOpts.empty()) { + baseOpts = newOpts; + return; + } + + std::vector extraOpts; + for (CIter fit = newOpts.begin(), fitEnd = newOpts.end(); fit != fitEnd; + ++fit) { + std::string const& newOpt = *fit; + Iter existIt = std::find(baseOpts.begin(), baseOpts.end(), newOpt); + if (existIt != baseOpts.end()) { + if (newOpt.size() >= 2) { + // Acquire the option name + std::string optName; + { + auto oit = newOpt.begin(); + if (*oit == '-') { + ++oit; + if (isQt5 && (*oit == '-')) { + ++oit; + } + optName.assign(oit, newOpt.end()); + } + } + // Test if this is a value option and change the existing value + if (!optName.empty() && (std::find(valueOpts.begin(), valueOpts.end(), + optName) != valueOpts.end())) { + const Iter existItNext(existIt + 1); + const CIter fitNext(fit + 1); + if ((existItNext != baseOpts.end()) && (fitNext != fitEnd)) { + *existItNext = *fitNext; + ++fit; + } + } + } + } else { + extraOpts.push_back(newOpt); + } + } + // Append options + baseOpts.insert(baseOpts.end(), extraOpts.begin(), extraOpts.end()); +} + +static std::string utilStripCR(std::string const& line) +{ + // Strip CR characters rcc may have printed (possibly more than one!). + std::string::size_type cr = line.find('\r'); + if (cr != std::string::npos) { + return line.substr(0, cr); + } + return line; +} + +/// @brief Reads the resource files list from from a .qrc file - Qt4 version +/// @return True if the .qrc file was successfully parsed +static bool RccListInputsQt4(std::string const& fileName, + std::vector& files, + std::string* errorMessage) +{ + bool allGood = true; + // Read qrc file content into string + std::string qrcContents; + { + cmsys::ifstream ifs(fileName.c_str()); + if (ifs) { + std::ostringstream osst; + osst << ifs.rdbuf(); + qrcContents = osst.str(); + } else { + if (errorMessage != nullptr) { + std::ostringstream ost; + ost << "rcc file not readable:\n" + << " " << cmQtAutoGen::Quoted(fileName) << "\n"; + *errorMessage = ost.str(); + } + allGood = false; + } + } + if (allGood) { + // qrc file directory + std::string qrcDir(cmSystemTools::GetFilenamePath(fileName)); + if (!qrcDir.empty()) { + qrcDir += '/'; + } + + cmsys::RegularExpression fileMatchRegex("(]*>)"); + + size_t offset = 0; + while (fileMatchRegex.find(qrcContents.c_str() + offset)) { + std::string qrcEntry = fileMatchRegex.match(1); + offset += qrcEntry.size(); + { + fileReplaceRegex.find(qrcEntry); + std::string tag = fileReplaceRegex.match(1); + qrcEntry = qrcEntry.substr(tag.size()); + } + if (!cmSystemTools::FileIsFullPath(qrcEntry.c_str())) { + qrcEntry = qrcDir + qrcEntry; + } + files.push_back(qrcEntry); + } + } + return allGood; +} + +/// @brief Reads the resource files list from from a .qrc file - Qt5 version +/// @return True if the .qrc file was successfully parsed +static bool RccListInputsQt5(std::string const& rccCommand, + std::string const& fileName, + std::vector& files, + std::string* errorMessage) +{ + if (rccCommand.empty()) { + cmSystemTools::Error("rcc executable not available"); + return false; + } + + // Read rcc features + bool hasDashDashList = false; + { + std::vector command; + command.push_back(rccCommand); + command.push_back("--help"); + std::string rccStdOut; + std::string rccStdErr; + int retVal = 0; + bool result = cmSystemTools::RunSingleCommand( + command, &rccStdOut, &rccStdErr, &retVal, nullptr, + cmSystemTools::OUTPUT_NONE, 0.0, cmProcessOutput::Auto); + if (result && retVal == 0 && + rccStdOut.find("--list") != std::string::npos) { + hasDashDashList = true; + } + } + + std::string const fileDir = cmSystemTools::GetFilenamePath(fileName); + std::string const fileNameName = cmSystemTools::GetFilenameName(fileName); + + // Run rcc list command + bool result = false; + int retVal = 0; + std::string rccStdOut; + std::string rccStdErr; + { + std::vector command; + command.push_back(rccCommand); + command.push_back(hasDashDashList ? "--list" : "-list"); + command.push_back(fileNameName); + result = cmSystemTools::RunSingleCommand( + command, &rccStdOut, &rccStdErr, &retVal, fileDir.c_str(), + cmSystemTools::OUTPUT_NONE, 0.0, cmProcessOutput::Auto); + } + if (!result || retVal) { + if (errorMessage != nullptr) { + std::ostringstream ost; + ost << "rcc list process failed for\n " << cmQtAutoGen::Quoted(fileName) + << "\n" + << rccStdOut << "\n" + << rccStdErr << "\n"; + *errorMessage = ost.str(); + } + return false; + } + + // Parse rcc std output + { + std::istringstream ostr(rccStdOut); + std::string oline; + while (std::getline(ostr, oline)) { + oline = utilStripCR(oline); + if (!oline.empty()) { + files.push_back(oline); + } + } + } + // Parse rcc error output + { + std::istringstream estr(rccStdErr); + std::string eline; + while (std::getline(estr, eline)) { + eline = utilStripCR(eline); + if (cmHasLiteralPrefix(eline, "RCC: Error in")) { + static std::string searchString = "Cannot find file '"; + + std::string::size_type pos = eline.find(searchString); + if (pos == std::string::npos) { + if (errorMessage != nullptr) { + std::ostringstream ost; + ost << "rcc lists unparsable output:\n" + << cmQtAutoGen::Quoted(eline) << "\n"; + *errorMessage = ost.str(); + } + return false; + } + pos += searchString.length(); + std::string::size_type sz = eline.size() - pos - 1; + files.push_back(eline.substr(pos, sz)); + } + } + } + + // Convert relative paths to absolute paths + for (std::string& resFile : files) { + resFile = cmSystemTools::CollapseCombinedPath(fileDir, resFile); + } + + return true; +} + +// - Class definitions + +std::string const cmQtAutoGen::listSep = "@LSEP@"; + +std::string const& cmQtAutoGen::GeneratorName(Generator type) +{ + switch (type) { + case Generator::GEN: + return genNameGen; + case Generator::MOC: + return genNameMoc; + case Generator::UIC: + return genNameUic; + case Generator::RCC: + return genNameRcc; + } + return genNameGen; +} + +std::string cmQtAutoGen::GeneratorNameUpper(Generator genType) +{ + return cmSystemTools::UpperCase(cmQtAutoGen::GeneratorName(genType)); +} + +std::string const& cmQtAutoGen::MultiConfigName(MultiConfig config) +{ + switch (config) { + case MultiConfig::SINGLE: + return mcNameSingle; + case MultiConfig::WRAP: + return mcNameWrap; + case MultiConfig::FULL: + return mcNameFull; + } + return mcNameWrap; +} + +cmQtAutoGen::MultiConfig cmQtAutoGen::MultiConfigType(std::string const& name) +{ + if (name == mcNameSingle) { + return MultiConfig::SINGLE; + } + if (name == mcNameFull) { + return MultiConfig::FULL; + } + return MultiConfig::WRAP; +} + +std::string cmQtAutoGen::Quoted(std::string const& text) +{ + static const char* rep[18] = { "\\", "\\\\", "\"", "\\\"", "\a", "\\a", + "\b", "\\b", "\f", "\\f", "\n", "\\n", + "\r", "\\r", "\t", "\\t", "\v", "\\v" }; + + std::string res = text; + for (const char* const* it = cmArrayBegin(rep); it != cmArrayEnd(rep); + it += 2) { + cmSystemTools::ReplaceString(res, *it, *(it + 1)); + } + res = '"' + res; + res += '"'; + return res; +} + +std::string cmQtAutoGen::AppendFilenameSuffix(std::string const& filename, + std::string const& suffix) +{ + std::string res; + auto pos = filename.rfind('.'); + if (pos != std::string::npos) { + const auto it_dot = filename.begin() + pos; + res.assign(filename.begin(), it_dot); + res.append(suffix); + res.append(it_dot, filename.end()); + } else { + res = filename; + res.append(suffix); + } + return res; +} + +void cmQtAutoGen::UicMergeOptions(std::vector& baseOpts, + std::vector const& newOpts, + bool isQt5) +{ + static std::vector const valueOpts = { + "tr", "translate", "postfix", "generator", + "include", // Since Qt 5.3 + "g" + }; + MergeOptions(baseOpts, newOpts, valueOpts, isQt5); +} + +void cmQtAutoGen::RccMergeOptions(std::vector& baseOpts, + std::vector const& newOpts, + bool isQt5) +{ + static std::vector const valueOpts = { "name", "root", + "compress", + "threshold" }; + MergeOptions(baseOpts, newOpts, valueOpts, isQt5); +} + +bool cmQtAutoGen::RccListInputs(std::string const& qtMajorVersion, + std::string const& rccCommand, + std::string const& fileName, + std::vector& files, + std::string* errorMessage) +{ + bool allGood = false; + if (cmSystemTools::FileExists(fileName.c_str())) { + if (qtMajorVersion == "4") { + allGood = RccListInputsQt4(fileName, files, errorMessage); + } else { + allGood = RccListInputsQt5(rccCommand, fileName, files, errorMessage); + } + } else { + if (errorMessage != nullptr) { + std::ostringstream ost; + ost << "rcc file does not exist:\n" + << " " << cmQtAutoGen::Quoted(fileName) << "\n"; + *errorMessage = ost.str(); + } + } + return allGood; +} diff --git a/Source/cmQtAutoGen.h b/Source/cmQtAutoGen.h new file mode 100644 index 000000000..acc092fb3 --- /dev/null +++ b/Source/cmQtAutoGen.h @@ -0,0 +1,72 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmQtAutoGen_h +#define cmQtAutoGen_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include +#include + +/** \class cmQtAutoGen + * \brief Class used as namespace for QtAutogen related types and functions + */ +class cmQtAutoGen +{ +public: + static std::string const listSep; + + enum Generator + { + GEN, // General + MOC, + UIC, + RCC + }; + + enum MultiConfig + { + SINGLE, // Single configuration + WRAP, // Multi configuration using wrapper files + FULL // Full multi configuration using per config sources + }; + +public: + /// @brief Returns the generator name + static std::string const& GeneratorName(Generator genType); + /// @brief Returns the generator name in upper case + static std::string GeneratorNameUpper(Generator genType); + + /// @brief Returns the multi configuration name string + static std::string const& MultiConfigName(MultiConfig config); + /// @brief Returns the multi configuration type + static MultiConfig MultiConfigType(std::string const& name); + + /// @brief Returns a the string escaped and enclosed in quotes + static std::string Quoted(std::string const& text); + + /// @brief Appends the suffix to the filename before the last dot + static std::string AppendFilenameSuffix(std::string const& filename, + std::string const& suffix); + + /// @brief Merges newOpts into baseOpts + static void UicMergeOptions(std::vector& baseOpts, + std::vector const& newOpts, + bool isQt5); + + /// @brief Merges newOpts into baseOpts + static void RccMergeOptions(std::vector& baseOpts, + std::vector const& newOpts, + bool isQt5); + + /// @brief Reads the resource files list from from a .qrc file + /// @arg fileName Must be the absolute path of the .qrc file + /// @return True if the rcc file was successfully parsed + static bool RccListInputs(std::string const& qtMajorVersion, + std::string const& rccCommand, + std::string const& fileName, + std::vector& files, + std::string* errorMessage = nullptr); +}; + +#endif diff --git a/Source/cmQtAutoGenDigest.h b/Source/cmQtAutoGenDigest.h new file mode 100644 index 000000000..677c39792 --- /dev/null +++ b/Source/cmQtAutoGenDigest.h @@ -0,0 +1,64 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmQtAutoGenDigest_h +#define cmQtAutoGenDigest_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include +#include +#include + +class cmGeneratorTarget; + +class cmQtAutoGenDigestQrc +{ +public: + cmQtAutoGenDigestQrc() + : Generated(false) + , Unique(false) + { + } + +public: + std::string QrcFile; + std::string QrcName; + std::string PathChecksum; + std::string RccFile; + bool Generated; + bool Unique; + std::vector Options; + std::vector Resources; +}; + +/** \class cmQtAutoGenDigest + * \brief Filtered set of QtAutogen variables for a specific target + */ +class cmQtAutoGenDigest +{ +public: + cmQtAutoGenDigest(cmGeneratorTarget* target) + : Target(target) + , MocEnabled(false) + , UicEnabled(false) + , RccEnabled(false) + { + } + +public: + cmGeneratorTarget* Target; + std::string QtVersionMajor; + std::string QtVersionMinor; + bool MocEnabled; + bool UicEnabled; + bool RccEnabled; + std::vector Headers; + std::vector Sources; + std::vector Qrcs; +}; + +// Utility types +typedef std::unique_ptr cmQtAutoGenDigestUP; +typedef std::vector cmQtAutoGenDigestUPV; + +#endif diff --git a/Source/cmQtAutoGeneratorCommon.cxx b/Source/cmQtAutoGeneratorCommon.cxx deleted file mode 100644 index 3e1b58caa..000000000 --- a/Source/cmQtAutoGeneratorCommon.cxx +++ /dev/null @@ -1,216 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmQtAutoGeneratorCommon.h" -#include "cmAlgorithms.h" -#include "cmSystemTools.h" - -#include "cmsys/FStream.hxx" -#include "cmsys/RegularExpression.hxx" - -#include -#include - -// - Static functions - -static std::string utilStripCR(std::string const& line) -{ - // Strip CR characters rcc may have printed (possibly more than one!). - std::string::size_type cr = line.find('\r'); - if (cr != std::string::npos) { - return line.substr(0, cr); - } - return line; -} - -/// @brief Reads the resource files list from from a .qrc file - Qt4 version -/// @return True if the .qrc file was successfully parsed -static bool RccListInputsQt4(const std::string& fileName, - std::vector& files, - std::string* errorMessage) -{ - bool allGood = true; - // Read qrc file content into string - std::string qrcContents; - { - cmsys::ifstream ifs(fileName.c_str()); - if (ifs) { - std::ostringstream osst; - osst << ifs.rdbuf(); - qrcContents = osst.str(); - } else { - if (errorMessage != CM_NULLPTR) { - std::ostringstream ost; - ost << "AutoRcc: Error: Rcc file not readable:\n" - << cmQtAutoGeneratorCommon::Quoted(fileName) << "\n"; - *errorMessage = ost.str(); - } - allGood = false; - } - } - if (allGood) { - // qrc file directory - std::string qrcDir(cmsys::SystemTools::GetFilenamePath(fileName)); - if (!qrcDir.empty()) { - qrcDir += '/'; - } - - cmsys::RegularExpression fileMatchRegex("(]*>)"); - - size_t offset = 0; - while (fileMatchRegex.find(qrcContents.c_str() + offset)) { - std::string qrcEntry = fileMatchRegex.match(1); - offset += qrcEntry.size(); - { - fileReplaceRegex.find(qrcEntry); - std::string tag = fileReplaceRegex.match(1); - qrcEntry = qrcEntry.substr(tag.size()); - } - if (!cmSystemTools::FileIsFullPath(qrcEntry.c_str())) { - qrcEntry = qrcDir + qrcEntry; - } - files.push_back(qrcEntry); - } - } - return allGood; -} - -/// @brief Reads the resource files list from from a .qrc file - Qt5 version -/// @return True if the .qrc file was successfully parsed -static bool RccListInputsQt5(const std::string& rccCommand, - const std::string& fileName, - std::vector& files, - std::string* errorMessage) -{ - if (rccCommand.empty()) { - cmSystemTools::Error("AutoRcc: Error: rcc executable not available\n"); - return false; - } - - // Read rcc features - bool hasDashDashList = false; - { - std::vector command; - command.push_back(rccCommand); - command.push_back("--help"); - std::string rccStdOut; - std::string rccStdErr; - int retVal = 0; - bool result = - cmSystemTools::RunSingleCommand(command, &rccStdOut, &rccStdErr, &retVal, - CM_NULLPTR, cmSystemTools::OUTPUT_NONE); - if (result && retVal == 0 && - rccStdOut.find("--list") != std::string::npos) { - hasDashDashList = true; - } - } - - // Run rcc list command - bool result = false; - int retVal = 0; - std::string rccStdOut; - std::string rccStdErr; - { - std::vector command; - command.push_back(rccCommand); - command.push_back(hasDashDashList ? "--list" : "-list"); - command.push_back(fileName); - result = - cmSystemTools::RunSingleCommand(command, &rccStdOut, &rccStdErr, &retVal, - CM_NULLPTR, cmSystemTools::OUTPUT_NONE); - } - if (!result || retVal) { - if (errorMessage != CM_NULLPTR) { - std::ostringstream ost; - ost << "AutoRcc: Error: Rcc list process for " << fileName - << " failed:\n" - << rccStdOut << "\n" - << rccStdErr << "\n"; - *errorMessage = ost.str(); - } - return false; - } - - // Parse rcc std output - { - std::istringstream ostr(rccStdOut); - std::string oline; - while (std::getline(ostr, oline)) { - oline = utilStripCR(oline); - if (!oline.empty()) { - files.push_back(oline); - } - } - } - // Parse rcc error output - { - std::istringstream estr(rccStdErr); - std::string eline; - while (std::getline(estr, eline)) { - eline = utilStripCR(eline); - if (cmHasLiteralPrefix(eline, "RCC: Error in")) { - static std::string searchString = "Cannot find file '"; - - std::string::size_type pos = eline.find(searchString); - if (pos == std::string::npos) { - if (errorMessage != CM_NULLPTR) { - std::ostringstream ost; - ost << "AutoRcc: Error: Rcc lists unparsable output:\n" - << cmQtAutoGeneratorCommon::Quoted(eline) << "\n"; - *errorMessage = ost.str(); - } - return false; - } - pos += searchString.length(); - std::string::size_type sz = eline.size() - pos - 1; - files.push_back(eline.substr(pos, sz)); - } - } - } - - return true; -} - -// - Class definitions - -const char* cmQtAutoGeneratorCommon::listSep = "@LSEP@"; - -std::string cmQtAutoGeneratorCommon::Quoted(const std::string& text) -{ - static const char* rep[18] = { "\\", "\\\\", "\"", "\\\"", "\a", "\\a", - "\b", "\\b", "\f", "\\f", "\n", "\\n", - "\r", "\\r", "\t", "\\t", "\v", "\\v" }; - - std::string res = text; - for (const char* const* it = cmArrayBegin(rep); it != cmArrayEnd(rep); - it += 2) { - cmSystemTools::ReplaceString(res, *it, *(it + 1)); - } - res = '"' + res; - res += '"'; - return res; -} - -bool cmQtAutoGeneratorCommon::RccListInputs(const std::string& qtMajorVersion, - const std::string& rccCommand, - const std::string& fileName, - std::vector& files, - std::string* errorMessage) -{ - bool allGood = false; - if (cmsys::SystemTools::FileExists(fileName.c_str())) { - if (qtMajorVersion == "4") { - allGood = RccListInputsQt4(fileName, files, errorMessage); - } else { - allGood = RccListInputsQt5(rccCommand, fileName, files, errorMessage); - } - } else { - if (errorMessage != CM_NULLPTR) { - std::ostringstream ost; - ost << "AutoRcc: Error: Rcc file does not exist:\n" - << cmQtAutoGeneratorCommon::Quoted(fileName) << "\n"; - *errorMessage = ost.str(); - } - } - return allGood; -} diff --git a/Source/cmQtAutoGeneratorCommon.h b/Source/cmQtAutoGeneratorCommon.h deleted file mode 100644 index a131baf20..000000000 --- a/Source/cmQtAutoGeneratorCommon.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef cmQtAutoGeneratorCommon_h -#define cmQtAutoGeneratorCommon_h - -#include "cmConfigure.h" - -#include -#include - -class cmQtAutoGeneratorCommon -{ - // - Types and statics -public: - static const char* listSep; - - enum GeneratorType - { - MOC, - UIC, - RCC - }; - -public: - /// @brief Returns a the string escaped and enclosed in quotes - /// - static std::string Quoted(const std::string& text); - - /// @brief Reads the resource files list from from a .qrc file - /// @arg fileName Must be the absolute path of the .qrc file - /// @return True if the rcc file was successfully parsed - static bool RccListInputs(const std::string& qtMajorVersion, - const std::string& rccCommand, - const std::string& fileName, - std::vector& files, - std::string* errorMessage = CM_NULLPTR); -}; - -#endif diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 3e3be54d1..c7550e60e 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -1,57 +1,76 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmQtAutoGen.h" #include "cmQtAutoGeneratorInitializer.h" -#include "cmQtAutoGeneratorCommon.h" #include "cmAlgorithms.h" +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmFilePathChecksum.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" +#include "cmLinkItem.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmOutputConverter.h" +#include "cmPolicies.h" #include "cmSourceFile.h" #include "cmSourceGroup.h" #include "cmState.h" +#include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" #include "cm_sys_stat.h" #include "cmake.h" - -#if defined(_WIN32) && !defined(__CYGWIN__) -#include "cmGlobalVisualStudioGenerator.h" -#endif - -#include "cmConfigure.h" #include "cmsys/FStream.hxx" + #include +#include +#include #include #include +#include #include #include #include -static void utilCopyTargetProperty(cmTarget* destinationTarget, - cmTarget* sourceTarget, - const std::string& propertyName) +inline static const char* SafeString(const char* value) { - const char* propertyValue = sourceTarget->GetProperty(propertyName); - if (propertyValue) { - destinationTarget->SetProperty(propertyName, propertyValue); - } + return (value != nullptr) ? value : ""; } -inline static bool PropertyEnabled(cmSourceFile* sourceFile, const char* key) +inline static std::string GetSafeProperty(cmGeneratorTarget const* target, + const char* key) { - return cmSystemTools::IsOn(sourceFile->GetPropertyForUser(key)); + return std::string(SafeString(target->GetProperty(key))); } -static std::string GetSafeProperty(cmGeneratorTarget const* target, - const char* key) +inline static std::string GetSafeProperty(cmSourceFile const* sf, + const char* key) { - const char* tmp = target->GetProperty(key); - return std::string((tmp != CM_NULLPTR) ? tmp : ""); + return std::string(SafeString(sf->GetProperty(key))); +} + +static cmQtAutoGen::MultiConfig AutogenMultiConfig( + cmGlobalGenerator* globalGen) +{ + if (!globalGen->IsMultiConfig()) { + return cmQtAutoGen::SINGLE; + } + + // FIXME: Xcode does not support per-config sources, yet. + // (EXCLUDED_SOURCE_FILE_NAMES) + // if (globalGen->GetName().find("Xcode") != std::string::npos) { + // return cmQtAutoGen::FULL; + //} + + // FIXME: Visual Studio does not support per-config sources, yet. + // (EXCLUDED_SOURCE_FILE_NAMES) + // if (globalGen->GetName().find("Visual Studio") != std::string::npos) { + // return cmQtAutoGen::FULL; + //} + + return cmQtAutoGen::WRAP; } static std::string GetAutogenTargetName(cmGeneratorTarget const* target) @@ -84,43 +103,44 @@ static std::string GetAutogenTargetBuildDir(cmGeneratorTarget const* target) return targetDir; } -static std::string GetQtMajorVersion(cmGeneratorTarget const* target) +std::string cmQtAutoGeneratorInitializer::GetQtMajorVersion( + cmGeneratorTarget const* target) { cmMakefile* makefile = target->Target->GetMakefile(); - std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR"); - if (qtMajorVersion.empty()) { - qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); + std::string qtMajor = makefile->GetSafeDefinition("QT_VERSION_MAJOR"); + if (qtMajor.empty()) { + qtMajor = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); } const char* targetQtVersion = target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", ""); - if (targetQtVersion != CM_NULLPTR) { - qtMajorVersion = targetQtVersion; + if (targetQtVersion != nullptr) { + qtMajor = targetQtVersion; } - return qtMajorVersion; + return qtMajor; } -static std::string GetQtMinorVersion(cmGeneratorTarget const* target, - const std::string& qtMajorVersion) +std::string cmQtAutoGeneratorInitializer::GetQtMinorVersion( + cmGeneratorTarget const* target, std::string const& qtVersionMajor) { cmMakefile* makefile = target->Target->GetMakefile(); - std::string qtMinorVersion; - if (qtMajorVersion == "5") { - qtMinorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MINOR"); + std::string qtMinor; + if (qtVersionMajor == "5") { + qtMinor = makefile->GetSafeDefinition("Qt5Core_VERSION_MINOR"); } - if (qtMinorVersion.empty()) { - qtMinorVersion = makefile->GetSafeDefinition("QT_VERSION_MINOR"); + if (qtMinor.empty()) { + qtMinor = makefile->GetSafeDefinition("QT_VERSION_MINOR"); } const char* targetQtVersion = target->GetLinkInterfaceDependentStringProperty("QT_MINOR_VERSION", ""); - if (targetQtVersion != CM_NULLPTR) { - qtMinorVersion = targetQtVersion; + if (targetQtVersion != nullptr) { + qtMinor = targetQtVersion; } - return qtMinorVersion; + return qtMinor; } -static bool QtVersionGreaterOrEqual(const std::string& major, - const std::string& minor, +static bool QtVersionGreaterOrEqual(std::string const& major, + std::string const& minor, unsigned long requestMajor, unsigned long requestMinor) { @@ -134,76 +154,17 @@ static bool QtVersionGreaterOrEqual(const std::string& major, return false; } -static void GetCompileDefinitionsAndDirectories( - cmGeneratorTarget const* target, const std::string& config, - std::string& incs, std::string& defs) -{ - cmLocalGenerator* localGen = target->GetLocalGenerator(); - { - std::vector includeDirs; - // Get the include dirs for this target, without stripping the implicit - // include dirs off, see - // https://gitlab.kitware.com/cmake/cmake/issues/13667 - localGen->GetIncludeDirectories(includeDirs, target, "CXX", config, false); - incs = cmJoin(includeDirs, ";"); - } - { - std::set defines; - localGen->AddCompileDefinitions(defines, target, config, "CXX"); - defs += cmJoin(defines, ";"); - } -} - -static bool IsMultiConfig(cmGlobalGenerator* globalGen) -{ - // FIXME: Xcode does not support per-config sources, yet. - // (EXCLUDED_SOURCE_FILE_NAMES) - // Treat it as a single configuration generator meanwhile. - if (globalGen->GetName().find("Xcode") != std::string::npos) { - return false; - } - // FIXME: Visual Studio does not fully support per-config sources yet. - if (globalGen->GetName().find("Visual Studio") != std::string::npos) { - return false; - } - return globalGen->IsMultiConfig(); -} - -static std::vector GetConfigurations( - cmMakefile* makefile, std::string* config = CM_NULLPTR) -{ - std::vector configs; - { - std::string cfg = makefile->GetConfigurations(configs); - if (config != CM_NULLPTR) { - *config = cfg; - } - } - // Add empty configuration on demand - if (configs.empty()) { - configs.push_back(""); - } - return configs; -} - -static std::vector GetConfigurationSuffixes(cmMakefile* makefile) +static void GetConfigs(cmMakefile* makefile, std::string& configDefault, + std::vector& configsList) { - std::vector suffixes; - if (IsMultiConfig(makefile->GetGlobalGenerator())) { - makefile->GetConfigurations(suffixes); - for (std::vector::iterator it = suffixes.begin(); - it != suffixes.end(); ++it) { - it->insert(0, "_"); - } + configDefault = makefile->GetConfigurations(configsList); + if (configsList.empty()) { + configsList.push_back(configDefault); } - if (suffixes.empty()) { - suffixes.push_back(""); - } - return suffixes; } static void AddDefinitionEscaped(cmMakefile* makefile, const char* key, - const std::string& value) + std::string const& value) { makefile->AddDefinition(key, cmOutputConverter::EscapeForCMake(value).c_str()); @@ -216,290 +177,389 @@ static void AddDefinitionEscaped(cmMakefile* makefile, const char* key, key, cmOutputConverter::EscapeForCMake(cmJoin(values, ";")).c_str()); } -static bool AddToSourceGroup(cmMakefile* makefile, const std::string& fileName, - cmQtAutoGeneratorCommon::GeneratorType genType) +static void AddDefinitionEscaped(cmMakefile* makefile, const char* key, + const std::set& values) { - cmSourceGroup* sourceGroup = CM_NULLPTR; + makefile->AddDefinition( + key, cmOutputConverter::EscapeForCMake(cmJoin(values, ";")).c_str()); +} + +static void AddDefinitionEscaped( + cmMakefile* makefile, const char* key, + const std::vector>& lists) +{ + std::vector seplist; + for (const std::vector& list : lists) { + std::string blist = "{"; + blist += cmJoin(list, ";"); + blist += "}"; + seplist.push_back(std::move(blist)); + } + makefile->AddDefinition(key, cmOutputConverter::EscapeForCMake( + cmJoin(seplist, cmQtAutoGen::listSep)) + .c_str()); +} + +static bool AddToSourceGroup(cmMakefile* makefile, std::string const& fileName, + cmQtAutoGen::Generator genType) +{ + cmSourceGroup* sourceGroup = nullptr; // Acquire source group { - const char* groupName = CM_NULLPTR; - // Use generator specific group name - switch (genType) { - case cmQtAutoGeneratorCommon::MOC: - groupName = - makefile->GetState()->GetGlobalProperty("AUTOMOC_SOURCE_GROUP"); - break; - case cmQtAutoGeneratorCommon::RCC: - groupName = - makefile->GetState()->GetGlobalProperty("AUTORCC_SOURCE_GROUP"); - break; - default: - break; - } - // Use default group name on demand - if ((groupName == CM_NULLPTR) || (*groupName == 0)) { - groupName = - makefile->GetState()->GetGlobalProperty("AUTOGEN_SOURCE_GROUP"); - } - // Generate a source group on demand - if ((groupName != CM_NULLPTR) && (*groupName != 0)) { - { - const char* delimiter = - makefile->GetDefinition("SOURCE_GROUP_DELIMITER"); - if (delimiter == CM_NULLPTR) { - delimiter = "\\"; - } - std::vector folders = - cmSystemTools::tokenize(groupName, delimiter); - sourceGroup = makefile->GetSourceGroup(folders); - if (sourceGroup == CM_NULLPTR) { - makefile->AddSourceGroup(folders); - sourceGroup = makefile->GetSourceGroup(folders); + std::string property; + std::string groupName; + { + std::array props; + // Use generator specific group name + switch (genType) { + case cmQtAutoGen::MOC: + props[0] = "AUTOMOC_SOURCE_GROUP"; + break; + case cmQtAutoGen::RCC: + props[0] = "AUTORCC_SOURCE_GROUP"; + break; + default: + props[0] = "AUTOGEN_SOURCE_GROUP"; + break; + } + props[1] = "AUTOGEN_SOURCE_GROUP"; + for (std::string& prop : props) { + const char* propName = makefile->GetState()->GetGlobalProperty(prop); + if ((propName != nullptr) && (*propName != '\0')) { + groupName = propName; + property = std::move(prop); + break; } } - if (sourceGroup == CM_NULLPTR) { - cmSystemTools::Error( - "Autogen: Could not create or find source group: ", - cmQtAutoGeneratorCommon::Quoted(groupName).c_str()); + } + // Generate a source group on demand + if (!groupName.empty()) { + sourceGroup = makefile->GetOrCreateSourceGroup(groupName); + if (sourceGroup == nullptr) { + std::ostringstream ost; + ost << cmQtAutoGen::GeneratorNameUpper(genType); + ost << ": " << property; + ost << ": Could not find or create the source group "; + ost << cmQtAutoGen::Quoted(groupName); + cmSystemTools::Error(ost.str().c_str()); return false; } } } - if (sourceGroup != CM_NULLPTR) { + if (sourceGroup != nullptr) { sourceGroup->AddGroupFile(fileName); } return true; } -static void AddGeneratedSource(cmMakefile* makefile, - const std::string& filename, - cmQtAutoGeneratorCommon::GeneratorType genType) +static void AddCleanFile(cmMakefile* makefile, std::string const& fileName) { - cmSourceFile* gFile = makefile->GetOrCreateSource(filename, true); - gFile->SetProperty("GENERATED", "1"); - gFile->SetProperty("SKIP_AUTOGEN", "On"); - - AddToSourceGroup(makefile, filename, genType); + makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", fileName.c_str(), + false); } -static void AcquireScanFiles(cmGeneratorTarget const* target, - std::vector& mocUicSources, - std::vector& mocUicHeaders, - std::vector& mocSkipList, - std::vector& uicSkipList) +static std::vector AddGeneratedSource( + cmGeneratorTarget* target, std::string const& filename, + cmQtAutoGen::MultiConfig multiConfig, + const std::vector& configsList, cmQtAutoGen::Generator genType) { - const bool mocTarget = target->GetPropertyAsBool("AUTOMOC"); - const bool uicTarget = target->GetPropertyAsBool("AUTOUIC"); - - std::vector srcFiles; - target->GetConfigCommonSourceFiles(srcFiles); - for (std::vector::const_iterator fileIt = srcFiles.begin(); - fileIt != srcFiles.end(); ++fileIt) { - cmSourceFile* sf = *fileIt; - const cmSystemTools::FileFormat fileType = - cmSystemTools::GetFileFormat(sf->GetExtension().c_str()); - - if (!(fileType == cmSystemTools::CXX_FILE_FORMAT) && - !(fileType == cmSystemTools::HEADER_FILE_FORMAT)) { - continue; + std::vector genFiles; + // Register source file in makefile and source group + if (multiConfig != cmQtAutoGen::FULL) { + genFiles.push_back(filename); + } else { + for (std::string const& cfg : configsList) { + genFiles.push_back( + cmQtAutoGen::AppendFilenameSuffix(filename, "_" + cfg)); } - if (PropertyEnabled(sf, "GENERATED") && - !target->GetPropertyAsBool("__UNDOCUMENTED_AUTOGEN_GENERATED_FILES")) { - // FIXME: Add a policy whose NEW behavior allows generated files. - // The implementation already works. We disable it here to avoid - // changing behavior for existing projects that do not expect it. - continue; + } + { + cmMakefile* makefile = target->Target->GetMakefile(); + for (std::string const& genFile : genFiles) { + { + cmSourceFile* gFile = makefile->GetOrCreateSource(genFile, true); + gFile->SetProperty("GENERATED", "1"); + gFile->SetProperty("SKIP_AUTOGEN", "On"); + } + AddToSourceGroup(makefile, genFile, genType); } - const std::string absFile = - cmsys::SystemTools::GetRealPath(sf->GetFullPath()); - // Skip flags - const bool skipAll = PropertyEnabled(sf, "SKIP_AUTOGEN"); - const bool mocSkip = skipAll || PropertyEnabled(sf, "SKIP_AUTOMOC"); - const bool uicSkip = skipAll || PropertyEnabled(sf, "SKIP_AUTOUIC"); - // Add file name to skip lists. - // Do this even when the file is not added to the sources/headers lists - // because the file name may be extracted from an other file when - // processing - if (mocSkip) { - mocSkipList.push_back(absFile); + } + + // Add source file to target + if (multiConfig != cmQtAutoGen::FULL) { + target->AddSource(filename); + } else { + for (std::string const& cfg : configsList) { + std::string src = "$<$AddSource(src); } - if (uicSkip) { - uicSkipList.push_back(absFile); + } + + return genFiles; +} + +/* @brief Tests if targetDepend is a STATIC_LIBRARY and if any of its + * recursive STATIC_LIBRARY dependencies depends on targetOrigin + * (STATIC_LIBRARY cycle). + */ +static bool StaticLibraryCycle(cmGeneratorTarget const* targetOrigin, + cmGeneratorTarget const* targetDepend, + std::string const& config) +{ + bool cycle = false; + if ((targetOrigin->GetType() == cmStateEnums::STATIC_LIBRARY) && + (targetDepend->GetType() == cmStateEnums::STATIC_LIBRARY)) { + std::set knownLibs; + std::deque testLibs; + + // Insert initial static_library dependency + knownLibs.insert(targetDepend); + testLibs.push_back(targetDepend); + + while (!testLibs.empty()) { + cmGeneratorTarget const* testTarget = testLibs.front(); + testLibs.pop_front(); + // Check if the test target is the origin target (cycle) + if (testTarget == targetOrigin) { + cycle = true; + break; + } + // Collect all static_library dependencies from the test target + cmLinkImplementationLibraries const* libs = + testTarget->GetLinkImplementationLibraries(config); + if (libs != nullptr) { + for (cmLinkItem const& item : libs->Libraries) { + cmGeneratorTarget const* depTarget = item.Target; + if ((depTarget != nullptr) && + (depTarget->GetType() == cmStateEnums::STATIC_LIBRARY) && + knownLibs.insert(depTarget).second) { + testLibs.push_back(depTarget); + } + } + } } + } + return cycle; +} - if ((mocTarget && !mocSkip) || (uicTarget && !uicSkip)) { - // Add file name to sources or headers list - switch (fileType) { - case cmSystemTools::CXX_FILE_FORMAT: - mocUicSources.push_back(absFile); - break; - case cmSystemTools::HEADER_FILE_FORMAT: - mocUicHeaders.push_back(absFile); - break; - default: - break; +struct cmQtAutoGenSetup +{ + std::set MocSkip; + std::set UicSkip; + + std::map ConfigMocIncludes; + std::map ConfigMocDefines; + std::map ConfigUicOptions; +}; + +static void SetupAcquireSkipFiles(cmQtAutoGenDigest const& digest, + cmQtAutoGenSetup& setup) +{ + // Read skip files from makefile sources + { + const std::vector& allSources = + digest.Target->Makefile->GetSourceFiles(); + for (cmSourceFile* sf : allSources) { + // sf->GetExtension() is only valid after sf->GetFullPath() ... + std::string const& fPath = sf->GetFullPath(); + cmSystemTools::FileFormat const fileType = + cmSystemTools::GetFileFormat(sf->GetExtension().c_str()); + if (!(fileType == cmSystemTools::CXX_FILE_FORMAT) && + !(fileType == cmSystemTools::HEADER_FILE_FORMAT)) { + continue; + } + const bool skipAll = sf->GetPropertyAsBool("SKIP_AUTOGEN"); + const bool mocSkip = digest.MocEnabled && + (skipAll || sf->GetPropertyAsBool("SKIP_AUTOMOC")); + const bool uicSkip = digest.UicEnabled && + (skipAll || sf->GetPropertyAsBool("SKIP_AUTOUIC")); + if (mocSkip || uicSkip) { + std::string const absFile = cmSystemTools::GetRealPath(fPath); + if (mocSkip) { + setup.MocSkip.insert(absFile); + } + if (uicSkip) { + setup.UicSkip.insert(absFile); + } } } } } -static void MocSetupAutoTarget( - cmGeneratorTarget const* target, const std::string& autogenTargetName, - std::string const& qtMajorVersion, std::string const& config, - std::vector const& configs, - std::vector const& mocSkipList, - std::map& configMocIncludes, - std::map& configMocDefines) +static void SetupAutoTargetMoc(cmQtAutoGenDigest const& digest, + std::string const& configDefault, + std::vector const& configsList, + cmQtAutoGenSetup& setup) { - cmLocalGenerator* lg = target->GetLocalGenerator(); + cmGeneratorTarget const* target = digest.Target; + cmLocalGenerator* localGen = target->GetLocalGenerator(); cmMakefile* makefile = target->Target->GetMakefile(); + AddDefinitionEscaped(makefile, "_moc_skip", setup.MocSkip); AddDefinitionEscaped(makefile, "_moc_options", GetSafeProperty(target, "AUTOMOC_MOC_OPTIONS")); - AddDefinitionEscaped(makefile, "_moc_skip", mocSkipList); AddDefinitionEscaped(makefile, "_moc_relaxed_mode", makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE") ? "TRUE" : "FALSE"); + AddDefinitionEscaped(makefile, "_moc_macro_names", + GetSafeProperty(target, "AUTOMOC_MACRO_NAMES")); AddDefinitionEscaped(makefile, "_moc_depend_filters", GetSafeProperty(target, "AUTOMOC_DEPEND_FILTERS")); - if (QtVersionGreaterOrEqual( - qtMajorVersion, GetQtMinorVersion(target, qtMajorVersion), 5, 8)) { - AddDefinitionEscaped( - makefile, "_moc_predefs_cmd", - makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND")); + // Compiler predefines + if (target->GetPropertyAsBool("AUTOMOC_COMPILER_PREDEFINES")) { + if (QtVersionGreaterOrEqual(digest.QtVersionMajor, digest.QtVersionMinor, + 5, 8)) { + AddDefinitionEscaped( + makefile, "_moc_predefs_cmd", + makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND")); + } } // Moc includes and compile definitions { - // Default settings - std::string incs; - std::string compileDefs; - GetCompileDefinitionsAndDirectories(target, config, incs, compileDefs); - AddDefinitionEscaped(makefile, "_moc_incs", incs); - AddDefinitionEscaped(makefile, "_moc_compile_defs", compileDefs); - - // Configuration specific settings - for (std::vector::const_iterator li = configs.begin(); - li != configs.end(); ++li) { - std::string configIncs; - std::string configCompileDefs; - GetCompileDefinitionsAndDirectories(target, *li, configIncs, - configCompileDefs); - if (configIncs != incs) { - configMocIncludes[*li] = cmOutputConverter::EscapeForCMake(configIncs); + auto GetIncludeDirs = [target, + localGen](std::string const& cfg) -> std::string { + // Get the include dirs for this target, without stripping the implicit + // include dirs off, see + // https://gitlab.kitware.com/cmake/cmake/issues/13667 + std::vector includeDirs; + localGen->GetIncludeDirectories(includeDirs, target, "CXX", cfg, false); + return cmJoin(includeDirs, ";"); + }; + auto GetCompileDefinitions = + [target, localGen](std::string const& cfg) -> std::string { + std::set defines; + localGen->AddCompileDefinitions(defines, target, cfg, "CXX"); + return cmJoin(defines, ";"); + }; + + // Default configuration settings + std::string const includeDirs = GetIncludeDirs(configDefault); + std::string const compileDefs = GetCompileDefinitions(configDefault); + // Other configuration settings + for (std::string const& cfg : configsList) { + { + std::string const configIncludeDirs = GetIncludeDirs(cfg); + if (configIncludeDirs != includeDirs) { + setup.ConfigMocIncludes[cfg] = configIncludeDirs; + } } - if (configCompileDefs != compileDefs) { - configMocDefines[*li] = - cmOutputConverter::EscapeForCMake(configCompileDefs); + { + std::string const configCompileDefs = GetCompileDefinitions(cfg); + if (configCompileDefs != compileDefs) { + setup.ConfigMocDefines[cfg] = configCompileDefs; + } } } + AddDefinitionEscaped(makefile, "_moc_include_dirs", includeDirs); + AddDefinitionEscaped(makefile, "_moc_compile_defs", compileDefs); } // Moc executable { + std::string mocExec; std::string err; - const char* mocExec = CM_NULLPTR; - if (qtMajorVersion == "5") { - cmGeneratorTarget* qt5Moc = lg->FindGeneratorTargetToUse("Qt5::moc"); - if (qt5Moc != CM_NULLPTR) { - mocExec = qt5Moc->ImportedGetLocation(""); + + if (digest.QtVersionMajor == "5") { + cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse("Qt5::moc"); + if (tgt != nullptr) { + mocExec = SafeString(tgt->ImportedGetLocation("")); } else { - err = "Qt5::moc target not found " + autogenTargetName; + err = "AUTOMOC: Qt5::moc target not found"; } - } else if (qtMajorVersion == "4") { - cmGeneratorTarget* qt4Moc = lg->FindGeneratorTargetToUse("Qt4::moc"); - if (qt4Moc != CM_NULLPTR) { - mocExec = qt4Moc->ImportedGetLocation(""); + } else if (digest.QtVersionMajor == "4") { + cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse("Qt4::moc"); + if (tgt != nullptr) { + mocExec = SafeString(tgt->ImportedGetLocation("")); } else { - err = "Qt4::moc target not found " + autogenTargetName; + err = "AUTOMOC: Qt4::moc target not found"; } } else { - err = "The CMAKE_AUTOMOC feature supports only Qt 4 and Qt 5 "; - err += autogenTargetName; + err = "The AUTOMOC feature supports only Qt 4 and Qt 5"; } - // Add definition or error + if (err.empty()) { - AddDefinitionEscaped(makefile, "_qt_moc_executable", - mocExec ? mocExec : ""); + AddDefinitionEscaped(makefile, "_qt_moc_executable", mocExec); } else { + err += " (" + target->GetName() + ")"; cmSystemTools::Error(err.c_str()); } } } -static void UicGetOpts(cmGeneratorTarget const* target, - const std::string& config, std::string& optString) +static void SetupAutoTargetUic(cmQtAutoGenDigest const& digest, + std::string const& config, + std::vector const& configs, + cmQtAutoGenSetup& setup) { - std::vector opts; - target->GetAutoUicOptions(opts, config); - optString = cmJoin(opts, ";"); -} - -static void UicSetupAutoTarget( - cmGeneratorTarget const* target, std::string const& qtMajorVersion, - std::string const& config, std::vector const& configs, - std::vector const& uicSkipList, - std::map& configUicOptions) -{ - cmLocalGenerator* lg = target->GetLocalGenerator(); + cmGeneratorTarget const* target = digest.Target; cmMakefile* makefile = target->Target->GetMakefile(); - AddDefinitionEscaped(makefile, "_uic_skip", uicSkipList); - // Uic search paths { std::vector uicSearchPaths; - cmSystemTools::ExpandListArgument( - GetSafeProperty(target, "AUTOUIC_SEARCH_PATHS"), uicSearchPaths); - const std::string srcDir = makefile->GetCurrentSourceDirectory(); - for (std::vector::iterator it = uicSearchPaths.begin(); - it != uicSearchPaths.end(); ++it) { - *it = cmSystemTools::CollapseFullPath(*it, srcDir); + { + std::string const usp = GetSafeProperty(target, "AUTOUIC_SEARCH_PATHS"); + if (!usp.empty()) { + cmSystemTools::ExpandListArgument(usp, uicSearchPaths); + std::string const srcDir = makefile->GetCurrentSourceDirectory(); + for (std::string& path : uicSearchPaths) { + path = cmSystemTools::CollapseFullPath(path, srcDir); + } + } } AddDefinitionEscaped(makefile, "_uic_search_paths", uicSearchPaths); } // Uic target options { + auto UicGetOpts = [target](std::string const& cfg) -> std::string { + std::vector opts; + target->GetAutoUicOptions(opts, cfg); + return cmJoin(opts, ";"); + }; + // Default settings - std::string uicOpts; - UicGetOpts(target, config, uicOpts); + std::string const uicOpts = UicGetOpts(config); AddDefinitionEscaped(makefile, "_uic_target_options", uicOpts); // Configuration specific settings - for (std::vector::const_iterator li = configs.begin(); - li != configs.end(); ++li) { - std::string configUicOpts; - UicGetOpts(target, *li, configUicOpts); + for (std::string const& cfg : configs) { + std::string const configUicOpts = UicGetOpts(cfg); if (configUicOpts != uicOpts) { - configUicOptions[*li] = - cmOutputConverter::EscapeForCMake(configUicOpts); + setup.ConfigUicOptions[cfg] = configUicOpts; } } } - // Uic files options + // .ui files skip and options { std::vector uiFileFiles; - std::vector uiFileOptions; + std::vector> uiFileOptions; { - std::set skipped; - skipped.insert(uicSkipList.begin(), uicSkipList.end()); - - const std::vector uiFilesWithOptions = - makefile->GetQtUiFilesWithOptions(); - for (std::vector::const_iterator fileIt = - uiFilesWithOptions.begin(); - fileIt != uiFilesWithOptions.end(); ++fileIt) { - cmSourceFile* sf = *fileIt; - const std::string absFile = - cmsys::SystemTools::GetRealPath(sf->GetFullPath()); - if (skipped.insert(absFile).second) { - // The file wasn't skipped - uiFileFiles.push_back(absFile); - { - std::string opts = sf->GetProperty("AUTOUIC_OPTIONS"); - cmSystemTools::ReplaceString(opts, ";", - cmQtAutoGeneratorCommon::listSep); - uiFileOptions.push_back(opts); + std::string const uiExt = "ui"; + for (cmSourceFile* sf : makefile->GetSourceFiles()) { + // sf->GetExtension() is only valid after sf->GetFullPath() ... + std::string const& fPath = sf->GetFullPath(); + if (sf->GetExtension() == uiExt) { + std::string const absFile = cmSystemTools::GetRealPath(fPath); + // Check if the file should be skipped + if (sf->GetPropertyAsBool("SKIP_AUTOUIC") || + sf->GetPropertyAsBool("SKIP_AUTOGEN")) { + setup.UicSkip.insert(absFile); + } + // Check if the files has uic options + std::string const uicOpts = GetSafeProperty(sf, "AUTOUIC_OPTIONS"); + if (!uicOpts.empty()) { + // Check if file isn't skipped + if (setup.UicSkip.count(absFile) == 0) { + uiFileFiles.push_back(absFile); + std::vector optsVec; + cmSystemTools::ExpandListArgument(uicOpts, optsVec); + uiFileOptions.push_back(std::move(optsVec)); + } } } } @@ -508,233 +568,134 @@ static void UicSetupAutoTarget( AddDefinitionEscaped(makefile, "_qt_uic_options_options", uiFileOptions); } + AddDefinitionEscaped(makefile, "_uic_skip", setup.UicSkip); + // Uic executable { std::string err; - const char* uicExec = CM_NULLPTR; - if (qtMajorVersion == "5") { - cmGeneratorTarget* qt5Uic = lg->FindGeneratorTargetToUse("Qt5::uic"); - if (qt5Uic != CM_NULLPTR) { - uicExec = qt5Uic->ImportedGetLocation(""); + std::string uicExec; + + cmLocalGenerator* localGen = target->GetLocalGenerator(); + if (digest.QtVersionMajor == "5") { + cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse("Qt5::uic"); + if (tgt != nullptr) { + uicExec = SafeString(tgt->ImportedGetLocation("")); } else { // Project does not use Qt5Widgets, but has AUTOUIC ON anyway } - } else if (qtMajorVersion == "4") { - cmGeneratorTarget* qt4Uic = lg->FindGeneratorTargetToUse("Qt4::uic"); - if (qt4Uic != CM_NULLPTR) { - uicExec = qt4Uic->ImportedGetLocation(""); + } else if (digest.QtVersionMajor == "4") { + cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse("Qt4::uic"); + if (tgt != nullptr) { + uicExec = SafeString(tgt->ImportedGetLocation("")); } else { - err = "Qt4::uic target not found " + target->GetName(); + err = "AUTOUIC: Qt4::uic target not found"; } } else { - err = "The CMAKE_AUTOUIC feature supports only Qt 4 and Qt 5 "; - err += target->GetName(); + err = "The AUTOUIC feature supports only Qt 4 and Qt 5"; } - // Add definition or error + if (err.empty()) { - AddDefinitionEscaped(makefile, "_qt_uic_executable", - uicExec ? uicExec : ""); + AddDefinitionEscaped(makefile, "_qt_uic_executable", uicExec); } else { + err += " (" + target->GetName() + ")"; cmSystemTools::Error(err.c_str()); } } } static std::string RccGetExecutable(cmGeneratorTarget const* target, - const std::string& qtMajorVersion) + std::string const& qtMajorVersion) { std::string rccExec; - cmLocalGenerator* lg = target->GetLocalGenerator(); + std::string err; + + cmLocalGenerator* localGen = target->GetLocalGenerator(); if (qtMajorVersion == "5") { - cmGeneratorTarget* qt5Rcc = lg->FindGeneratorTargetToUse("Qt5::rcc"); - if (qt5Rcc != CM_NULLPTR) { - rccExec = qt5Rcc->ImportedGetLocation(""); + cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse("Qt5::rcc"); + if (tgt != nullptr) { + rccExec = SafeString(tgt->ImportedGetLocation("")); } else { - cmSystemTools::Error("Qt5::rcc target not found ", - target->GetName().c_str()); + err = "AUTORCC: Qt5::rcc target not found"; } } else if (qtMajorVersion == "4") { - cmGeneratorTarget* qt4Rcc = lg->FindGeneratorTargetToUse("Qt4::rcc"); - if (qt4Rcc != CM_NULLPTR) { - rccExec = qt4Rcc->ImportedGetLocation(""); + cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse("Qt4::rcc"); + if (tgt != nullptr) { + rccExec = SafeString(tgt->ImportedGetLocation("")); } else { - cmSystemTools::Error("Qt4::rcc target not found ", - target->GetName().c_str()); + err = "AUTORCC: Qt4::rcc target not found"; } } else { - cmSystemTools::Error( - "The CMAKE_AUTORCC feature supports only Qt 4 and Qt 5 ", - target->GetName().c_str()); + err = "The AUTORCC feature supports only Qt 4 and Qt 5"; } - return rccExec; -} -static void RccMergeOptions(std::vector& opts, - const std::vector& fileOpts, - bool isQt5) -{ - static const char* valueOptions[] = { "name", "root", "compress", - "threshold" }; - std::vector extraOpts; - for (std::vector::const_iterator fit = fileOpts.begin(); - fit != fileOpts.end(); ++fit) { - std::vector::iterator existingIt = - std::find(opts.begin(), opts.end(), *fit); - if (existingIt != opts.end()) { - const char* optName = fit->c_str(); - if (*optName == '-') { - ++optName; - if (isQt5 && *optName == '-') { - ++optName; - } - } - // Test if this is a value option and change the existing value - if ((optName != fit->c_str()) && - std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions), - cmStrCmp(optName)) != cmArrayEnd(valueOptions)) { - const std::vector::iterator existValueIt(existingIt + 1); - const std::vector::const_iterator fileValueIt(fit + 1); - if ((existValueIt != opts.end()) && (fileValueIt != fileOpts.end())) { - *existValueIt = *fileValueIt; - ++fit; - } - } - } else { - extraOpts.push_back(*fit); - } + if (!err.empty()) { + err += " (" + target->GetName() + ")"; + cmSystemTools::Error(err.c_str()); } - opts.insert(opts.end(), extraOpts.begin(), extraOpts.end()); + return rccExec; } -static void RccSetupAutoTarget(cmGeneratorTarget const* target, - const std::string& qtMajorVersion) +static void SetupAutoTargetRcc(cmQtAutoGenDigest const& digest) { - cmMakefile* makefile = target->Target->GetMakefile(); - const bool qtMajorVersion5 = (qtMajorVersion == "5"); - const std::string rccCommand = RccGetExecutable(target, qtMajorVersion); - std::vector _rcc_files; - std::vector _rcc_inputs; - std::vector rccFileFiles; - std::vector rccFileOptions; - std::vector rccOptionsTarget; - if (const char* opts = target->GetProperty("AUTORCC_OPTIONS")) { - cmSystemTools::ExpandListArgument(opts, rccOptionsTarget); + std::vector rccFiles; + std::vector rccBuilds; + std::vector> rccOptions; + std::vector> rccInputs; + + for (cmQtAutoGenDigestQrc const& qrcDigest : digest.Qrcs) { + rccFiles.push_back(qrcDigest.QrcFile); + rccBuilds.push_back(qrcDigest.RccFile); + rccOptions.push_back(qrcDigest.Options); + rccInputs.push_back(qrcDigest.Resources); } - std::vector srcFiles; - target->GetConfigCommonSourceFiles(srcFiles); - for (std::vector::const_iterator fileIt = srcFiles.begin(); - fileIt != srcFiles.end(); ++fileIt) { - cmSourceFile* sf = *fileIt; - if ((sf->GetExtension() == "qrc") && - !PropertyEnabled(sf, "SKIP_AUTOGEN") && - !PropertyEnabled(sf, "SKIP_AUTORCC")) { - const std::string absFile = - cmsys::SystemTools::GetRealPath(sf->GetFullPath()); - // qrc file - _rcc_files.push_back(absFile); - // qrc file entries - { - std::string entriesList = "{"; - // Read input file list only for non generated .qrc files. - if (!PropertyEnabled(sf, "GENERATED")) { - std::string error; - std::vector files; - if (cmQtAutoGeneratorCommon::RccListInputs( - qtMajorVersion, rccCommand, absFile, files, &error)) { - entriesList += cmJoin(files, cmQtAutoGeneratorCommon::listSep); - } else { - cmSystemTools::Error(error.c_str()); - } - } - entriesList += "}"; - _rcc_inputs.push_back(entriesList); - } - // rcc options for this qrc file - { - // Merged target and file options - std::vector rccOptions(rccOptionsTarget); - if (const char* prop = sf->GetProperty("AUTORCC_OPTIONS")) { - std::vector optsVec; - cmSystemTools::ExpandListArgument(prop, optsVec); - RccMergeOptions(rccOptions, optsVec, qtMajorVersion5); - } - // Only store non empty options lists - if (!rccOptions.empty()) { - rccFileFiles.push_back(absFile); - rccFileOptions.push_back( - cmJoin(rccOptions, cmQtAutoGeneratorCommon::listSep)); - } - } - } - } - - AddDefinitionEscaped(makefile, "_qt_rcc_executable", rccCommand); - AddDefinitionEscaped(makefile, "_rcc_files", _rcc_files); - AddDefinitionEscaped(makefile, "_rcc_inputs", _rcc_inputs); - AddDefinitionEscaped(makefile, "_rcc_options_files", rccFileFiles); - AddDefinitionEscaped(makefile, "_rcc_options_options", rccFileOptions); -} - -void cmQtAutoGeneratorInitializer::InitializeAutogenSources( - cmGeneratorTarget* target) -{ - if (target->GetPropertyAsBool("AUTOMOC")) { - cmMakefile* makefile = target->Target->GetMakefile(); - const std::vector suffixes = - GetConfigurationSuffixes(makefile); - // Get build directory - const std::string autogenBuildDir = GetAutogenTargetBuildDir(target); - // Register all compilation files as generated - for (std::vector::const_iterator it = suffixes.begin(); - it != suffixes.end(); ++it) { - std::string mcFile = autogenBuildDir + "/mocs_compilation"; - mcFile += *it; - mcFile += ".cpp"; - AddGeneratedSource(makefile, mcFile, cmQtAutoGeneratorCommon::MOC); - } - // Mocs compilation file - if (IsMultiConfig(target->GetGlobalGenerator())) { - target->AddSource(autogenBuildDir + "/mocs_compilation_$.cpp"); - } else { - target->AddSource(autogenBuildDir + "/mocs_compilation.cpp"); - } - } + cmMakefile* makefile = digest.Target->Target->GetMakefile(); + AddDefinitionEscaped(makefile, "_qt_rcc_executable", + RccGetExecutable(digest.Target, digest.QtVersionMajor)); + AddDefinitionEscaped(makefile, "_rcc_files", rccFiles); + AddDefinitionEscaped(makefile, "_rcc_builds", rccBuilds); + AddDefinitionEscaped(makefile, "_rcc_options", rccOptions); + AddDefinitionEscaped(makefile, "_rcc_inputs", rccInputs); } void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( - cmLocalGenerator* lg, cmGeneratorTarget* target) + cmQtAutoGenDigest& digest) { + cmGeneratorTarget* target = digest.Target; cmMakefile* makefile = target->Target->GetMakefile(); + cmLocalGenerator* localGen = target->GetLocalGenerator(); + cmGlobalGenerator* globalGen = localGen->GetGlobalGenerator(); - // Create a custom target for running generators at buildtime - const bool mocEnabled = target->GetPropertyAsBool("AUTOMOC"); - const bool uicEnabled = target->GetPropertyAsBool("AUTOUIC"); - const bool rccEnabled = target->GetPropertyAsBool("AUTORCC"); - const bool multiConfig = IsMultiConfig(target->GetGlobalGenerator()); - const std::string autogenTargetName = GetAutogenTargetName(target); - const std::string autogenBuildDir = GetAutogenTargetBuildDir(target); - const std::string workingDirectory = + std::string const autogenTargetName = GetAutogenTargetName(target); + std::string const autogenInfoDir = GetAutogenTargetFilesDir(target); + std::string const autogenBuildDir = GetAutogenTargetBuildDir(target); + std::string const workingDirectory = cmSystemTools::CollapseFullPath("", makefile->GetCurrentBinaryDirectory()); - const std::string qtMajorVersion = GetQtMajorVersion(target); - const std::string rccCommand = RccGetExecutable(target, qtMajorVersion); - const std::vector suffixes = GetConfigurationSuffixes(makefile); - std::vector autogenDependFiles; - std::vector autogenDependTargets; + + cmQtAutoGen::MultiConfig const multiConfig = AutogenMultiConfig(globalGen); + std::string configDefault; + std::vector configsList; + GetConfigs(makefile, configDefault, configsList); + + std::set autogenDependFiles; + std::set autogenDependTargets; std::vector autogenProvides; // Remove build directories on cleanup - makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", - autogenBuildDir.c_str(), false); - + AddCleanFile(makefile, autogenBuildDir); // Remove old settings on cleanup { - std::string base = GetAutogenTargetFilesDir(target); - for (std::vector::const_iterator it = suffixes.begin(); - it != suffixes.end(); ++it) { - std::string fname = base + "/AutogenOldSettings" + *it + ".cmake"; - makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", fname.c_str(), - false); + std::string base = autogenInfoDir + "/AutogenOldSettings"; + if (multiConfig == cmQtAutoGen::SINGLE) { + AddCleanFile(makefile, base.append(".cmake")); + } else { + for (std::string const& cfg : configsList) { + std::string filename = base; + filename += "_"; + filename += cfg; + filename += ".cmake"; + AddCleanFile(makefile, filename); + } } } @@ -745,7 +706,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( currentLine.push_back(cmSystemTools::GetCMakeCommand()); currentLine.push_back("-E"); currentLine.push_back("cmake_autogen"); - currentLine.push_back(GetAutogenTargetFilesDir(target)); + currentLine.push_back(autogenInfoDir); currentLine.push_back("$"); commandLines.push_back(currentLine); } @@ -754,327 +715,477 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( std::string autogenComment; { std::vector toolNames; - if (mocEnabled) { - toolNames.push_back("MOC"); + if (digest.MocEnabled) { + toolNames.emplace_back("MOC"); } - if (uicEnabled) { - toolNames.push_back("UIC"); + if (digest.UicEnabled) { + toolNames.emplace_back("UIC"); } - if (rccEnabled) { - toolNames.push_back("RCC"); + if (digest.RccEnabled) { + toolNames.emplace_back("RCC"); } - std::string tools = toolNames[0]; + std::string tools = toolNames.front(); toolNames.erase(toolNames.begin()); - while (toolNames.size() > 1) { - tools += ", " + toolNames[0]; - toolNames.erase(toolNames.begin()); - } - if (toolNames.size() == 1) { - tools += " and " + toolNames[0]; + if (!toolNames.empty()) { + while (toolNames.size() > 1) { + tools += ", "; + tools += toolNames.front(); + toolNames.erase(toolNames.begin()); + } + tools += " and " + toolNames.front(); } autogenComment = "Automatic " + tools + " for target " + target->GetName(); } // Add moc compilation to generated files list - if (mocEnabled) { - for (std::vector::const_iterator it = suffixes.begin(); - it != suffixes.end(); ++it) { - std::string mcFile = autogenBuildDir + "/mocs_compilation"; - mcFile += *it; - mcFile += ".cpp"; - autogenProvides.push_back(mcFile); + if (digest.MocEnabled) { + std::string const mocsComp = autogenBuildDir + "/mocs_compilation.cpp"; + auto files = AddGeneratedSource(target, mocsComp, multiConfig, configsList, + cmQtAutoGen::MOC); + for (std::string& file : files) { + autogenProvides.push_back(std::move(file)); } } // Add autogen includes directory to the origin target INCLUDE_DIRECTORIES - if (mocEnabled || uicEnabled) { - if (multiConfig) { - target->AddIncludeDirectory(autogenBuildDir + "/include_$", - true); - - } else { - target->AddIncludeDirectory(autogenBuildDir + "/include", true); + if (digest.MocEnabled || digest.UicEnabled) { + std::string includeDir = autogenBuildDir + "/include"; + if (multiConfig != cmQtAutoGen::SINGLE) { + includeDir += "_$"; } + target->AddIncludeDirectory(includeDir, true); } -#if defined(_WIN32) && !defined(__CYGWIN__) - bool usePRE_BUILD = false; - cmGlobalGenerator* gg = lg->GetGlobalGenerator(); - if (gg->GetName().find("Visual Studio") != std::string::npos) { - // Under VS use a PRE_BUILD event instead of a separate target to - // reduce the number of targets loaded into the IDE. - // This also works around a VS 11 bug that may skip updating the target: - // https://connect.microsoft.com/VisualStudio/feedback/details/769495 - usePRE_BUILD = true; - } -#endif - - // Initialize autogen target dependencies - if (const char* extraDeps = target->GetProperty("AUTOGEN_TARGET_DEPENDS")) { - std::vector deps; - cmSystemTools::ExpandListArgument(extraDeps, deps); - for (std::vector::const_iterator itC = deps.begin(), - itE = deps.end(); - itC != itE; ++itC) { - if (makefile->FindTargetToUse(*itC) != CM_NULLPTR) { - autogenDependTargets.push_back(*itC); - } else { - autogenDependFiles.push_back(*itC); - } - } - } + // Extract relevant source files + std::vector generatedSources; + std::vector generatedHeaders; { - cmFilePathChecksum fpathCheckSum(makefile); - // Iterate over all source files + std::string const qrcExt = "qrc"; std::vector srcFiles; target->GetConfigCommonSourceFiles(srcFiles); - for (std::vector::const_iterator fileIt = srcFiles.begin(); - fileIt != srcFiles.end(); ++fileIt) { - cmSourceFile* sf = *fileIt; - if (!PropertyEnabled(sf, "SKIP_AUTOGEN")) { - std::string const& ext = sf->GetExtension(); - // Add generated file that will be scanned by moc or uic to - // the dependencies - if (mocEnabled || uicEnabled) { - const cmSystemTools::FileFormat fileType = - cmSystemTools::GetFileFormat(ext.c_str()); - if ((fileType == cmSystemTools::CXX_FILE_FORMAT) || - (fileType == cmSystemTools::HEADER_FILE_FORMAT)) { - if (PropertyEnabled(sf, "GENERATED")) { - if ((mocEnabled && !PropertyEnabled(sf, "SKIP_AUTOMOC")) || - (uicEnabled && !PropertyEnabled(sf, "SKIP_AUTOUIC"))) { - autogenDependFiles.push_back( - cmsys::SystemTools::GetRealPath(sf->GetFullPath())); -#if defined(_WIN32) && !defined(__CYGWIN__) - // Cannot use PRE_BUILD with generated files - usePRE_BUILD = false; -#endif + for (cmSourceFile* sf : srcFiles) { + if (sf->GetPropertyAsBool("SKIP_AUTOGEN")) { + continue; + } + // sf->GetExtension() is only valid after sf->GetFullPath() ... + std::string const& fPath = sf->GetFullPath(); + std::string const& ext = sf->GetExtension(); + // Register generated files that will be scanned by moc or uic + if (digest.MocEnabled || digest.UicEnabled) { + cmSystemTools::FileFormat const fileType = + cmSystemTools::GetFileFormat(ext.c_str()); + if ((fileType == cmSystemTools::CXX_FILE_FORMAT) || + (fileType == cmSystemTools::HEADER_FILE_FORMAT)) { + std::string const absPath = cmSystemTools::GetRealPath(fPath); + if ((digest.MocEnabled && !sf->GetPropertyAsBool("SKIP_AUTOMOC")) || + (digest.UicEnabled && !sf->GetPropertyAsBool("SKIP_AUTOUIC"))) { + // Register source + const bool generated = sf->GetPropertyAsBool("GENERATED"); + if (fileType == cmSystemTools::HEADER_FILE_FORMAT) { + if (generated) { + generatedHeaders.push_back(absPath); + } else { + digest.Headers.push_back(absPath); + } + } else { + if (generated) { + generatedSources.push_back(absPath); + } else { + digest.Sources.push_back(absPath); } } } } - // Process rcc enabled files - if (rccEnabled && (ext == "qrc") && - !PropertyEnabled(sf, "SKIP_AUTORCC")) { - const std::string absFile = - cmsys::SystemTools::GetRealPath(sf->GetFullPath()); - - // Compose rcc output file name + } + // Register rcc enabled files + if (digest.RccEnabled && (ext == qrcExt) && + !sf->GetPropertyAsBool("SKIP_AUTORCC")) { + // Register qrc file + { + cmQtAutoGenDigestQrc qrcDigest; + qrcDigest.QrcFile = cmSystemTools::GetRealPath(fPath); + qrcDigest.QrcName = + cmSystemTools::GetFilenameWithoutLastExtension(qrcDigest.QrcFile); + qrcDigest.Generated = sf->GetPropertyAsBool("GENERATED"); + // RCC options { - std::string rccOutBase = autogenBuildDir + "/"; - rccOutBase += fpathCheckSum.getPart(absFile); - rccOutBase += "/qrc_"; - rccOutBase += - cmsys::SystemTools::GetFilenameWithoutLastExtension(absFile); - - // Register rcc ouput file as generated - for (std::vector::const_iterator it = - suffixes.begin(); - it != suffixes.end(); ++it) { - std::string rccOutCfg = rccOutBase; - rccOutCfg += *it; - rccOutCfg += ".cpp"; - AddGeneratedSource(makefile, rccOutCfg, - cmQtAutoGeneratorCommon::RCC); - autogenProvides.push_back(rccOutCfg); - } - // Add rcc output file to origin target sources - if (multiConfig) { - target->AddSource(rccOutBase + "_$.cpp"); - } else { - target->AddSource(rccOutBase + ".cpp"); + std::string const opts = GetSafeProperty(sf, "AUTORCC_OPTIONS"); + if (!opts.empty()) { + cmSystemTools::ExpandListArgument(opts, qrcDigest.Options); } } + digest.Qrcs.push_back(std::move(qrcDigest)); + } + } + } + // cmGeneratorTarget::GetConfigCommonSourceFiles computes the target's + // sources meta data cache. Clear it so that OBJECT library targets that + // are AUTOGEN initialized after this target get their added + // mocs_compilation.cpp source acknowledged by this target. + target->ClearSourcesCache(); + } - if (PropertyEnabled(sf, "GENERATED")) { - // Add generated qrc file to the dependencies - autogenDependFiles.push_back(absFile); - } else { - // Run cmake again when .qrc file changes - makefile->AddCMakeDependFile(absFile); - - // Add the qrc input files to the dependencies - std::string error; - if (!cmQtAutoGeneratorCommon::RccListInputs( - qtMajorVersion, rccCommand, absFile, autogenDependFiles, - &error)) { - cmSystemTools::Error(error.c_str()); + // Process GENERATED sources and headers + if (!generatedSources.empty() || !generatedHeaders.empty()) { + // Check status of policy CMP0071 + bool policyAccept = false; + bool policyWarn = false; + cmPolicies::PolicyStatus const CMP0071_status = + target->Makefile->GetPolicyStatus(cmPolicies::CMP0071); + switch (CMP0071_status) { + case cmPolicies::WARN: + policyWarn = true; + CM_FALLTHROUGH; + case cmPolicies::OLD: + // Ignore GENERATED file + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + // Process GENERATED file + policyAccept = true; + break; + } + + if (policyAccept) { + // Accept GENERATED sources + for (std::string const& absFile : generatedHeaders) { + digest.Headers.push_back(absFile); + autogenDependFiles.insert(absFile); + } + for (std::string const& absFile : generatedSources) { + digest.Sources.push_back(absFile); + autogenDependFiles.insert(absFile); + } + } else { + if (policyWarn) { + std::string msg; + msg += cmPolicies::GetPolicyWarning(cmPolicies::CMP0071); + msg += "\n"; + std::string tools; + std::string property; + if (digest.MocEnabled && digest.UicEnabled) { + tools = "AUTOMOC and AUTOUIC"; + property = "SKIP_AUTOGEN"; + } else if (digest.MocEnabled) { + tools = "AUTOMOC"; + property = "SKIP_AUTOMOC"; + } else if (digest.UicEnabled) { + tools = "AUTOUIC"; + property = "SKIP_AUTOUIC"; + } + msg += "For compatibility, CMake is excluding the GENERATED source " + "file(s):\n"; + for (const std::string& absFile : generatedHeaders) { + msg.append(" ").append(cmQtAutoGen::Quoted(absFile)).append("\n"); + } + for (const std::string& absFile : generatedSources) { + msg.append(" ").append(cmQtAutoGen::Quoted(absFile)).append("\n"); + } + msg += "from processing by "; + msg += tools; + msg += + ". If any of the files should be processed, set CMP0071 to NEW. " + "If any of the files should not be processed, " + "explicitly exclude them by setting the source file property "; + msg += property; + msg += ":\n set_property(SOURCE file.h PROPERTY "; + msg += property; + msg += " ON)\n"; + makefile->IssueMessage(cmake::AUTHOR_WARNING, msg); + } + } + } + // Sort headers and sources + std::sort(digest.Headers.begin(), digest.Headers.end()); + std::sort(digest.Sources.begin(), digest.Sources.end()); + + // Process qrc files + if (!digest.Qrcs.empty()) { + const bool QtV5 = (digest.QtVersionMajor == "5"); + std::string const rcc = RccGetExecutable(target, digest.QtVersionMajor); + // Target rcc options + std::vector optionsTarget; + cmSystemTools::ExpandListArgument( + GetSafeProperty(target, "AUTORCC_OPTIONS"), optionsTarget); + + // Check if file name is unique + for (cmQtAutoGenDigestQrc& qrcDigest : digest.Qrcs) { + qrcDigest.Unique = true; + for (cmQtAutoGenDigestQrc const& qrcDig2 : digest.Qrcs) { + if ((&qrcDigest != &qrcDig2) && + (qrcDigest.QrcName == qrcDig2.QrcName)) { + qrcDigest.Unique = false; + break; + } + } + } + // Path checksum + { + cmFilePathChecksum const fpathCheckSum(makefile); + for (cmQtAutoGenDigestQrc& qrcDigest : digest.Qrcs) { + qrcDigest.PathChecksum = fpathCheckSum.getPart(qrcDigest.QrcFile); + // RCC output file name + std::string rccFile = autogenBuildDir + "/"; + rccFile += qrcDigest.PathChecksum; + rccFile += "/qrc_"; + rccFile += qrcDigest.QrcName; + rccFile += ".cpp"; + qrcDigest.RccFile = std::move(rccFile); + } + } + // RCC options + for (cmQtAutoGenDigestQrc& qrcDigest : digest.Qrcs) { + // Target options + std::vector opts = optionsTarget; + // Merge computed "-name XYZ" option + { + std::string name = qrcDigest.QrcName; + // Replace '-' with '_'. The former is not valid for symbol names. + std::replace(name.begin(), name.end(), '-', '_'); + if (!qrcDigest.Unique) { + name += "_"; + name += qrcDigest.PathChecksum; + } + std::vector nameOpts; + nameOpts.emplace_back("-name"); + nameOpts.emplace_back(std::move(name)); + cmQtAutoGen::RccMergeOptions(opts, nameOpts, QtV5); + } + // Merge file option + cmQtAutoGen::RccMergeOptions(opts, qrcDigest.Options, QtV5); + qrcDigest.Options = std::move(opts); + } + for (cmQtAutoGenDigestQrc& qrcDigest : digest.Qrcs) { + // Register file at target + { + auto files = AddGeneratedSource(target, qrcDigest.RccFile, multiConfig, + configsList, cmQtAutoGen::RCC); + for (std::string& file : files) { + autogenProvides.push_back(std::move(file)); + } + } + // Dependencies + if (qrcDigest.Generated) { + // Add the GENERATED .qrc file to the dependencies + autogenDependFiles.insert(qrcDigest.QrcFile); + } else { + // Add the resource files to the dependencies + { + std::string error; + if (cmQtAutoGen::RccListInputs(digest.QtVersionMajor, rcc, + qrcDigest.QrcFile, + qrcDigest.Resources, &error)) { + for (std::string const& fileName : qrcDigest.Resources) { + autogenDependFiles.insert(fileName); } + } else { + cmSystemTools::Error(error.c_str()); } -#if defined(_WIN32) && !defined(__CYGWIN__) - // Cannot use PRE_BUILD because the resource files themselves - // may not be sources within the target so VS may not know the - // target needs to re-build at all. - usePRE_BUILD = false; -#endif } + // Run cmake again when .qrc file changes + makefile->AddCMakeDependFile(qrcDigest.QrcFile); } } } -#if defined(_WIN32) && !defined(__CYGWIN__) + // Add user defined autogen target dependencies + { + std::string const deps = GetSafeProperty(target, "AUTOGEN_TARGET_DEPENDS"); + if (!deps.empty()) { + std::vector extraDeps; + cmSystemTools::ExpandListArgument(deps, extraDeps); + for (std::string const& depName : extraDeps) { + // Allow target and file dependencies + auto* depTarget = makefile->FindTargetToUse(depName); + if (depTarget != nullptr) { + autogenDependTargets.insert(depTarget); + } else { + autogenDependFiles.insert(depName); + } + } + } + } + + // Use PRE_BUILD on demand + bool usePRE_BUILD = false; + if (globalGen->GetName().find("Visual Studio") != std::string::npos) { + // Under VS use a PRE_BUILD event instead of a separate target to + // reduce the number of targets loaded into the IDE. + // This also works around a VS 11 bug that may skip updating the target: + // https://connect.microsoft.com/VisualStudio/feedback/details/769495 + usePRE_BUILD = true; + } + // Disable PRE_BUILD in some cases if (usePRE_BUILD) { - // We can't use pre-build if we depend on additional files + // Cannot use PRE_BUILD with file depends if (!autogenDependFiles.empty()) { usePRE_BUILD = false; } } + // Create the autogen target/command if (usePRE_BUILD) { + // Add additional autogen target dependencies to origin target + for (cmTarget* depTarget : autogenDependTargets) { + target->Target->AddUtility(depTarget->GetName(), makefile); + } + // Add the pre-build command directly to bypass the OBJECT_LIBRARY // rejection in cmMakefile::AddCustomCommandToTarget because we know // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case. - std::vector no_output; - std::vector no_depends; - cmCustomCommand cc(makefile, no_output, autogenProvides, no_depends, + // + // PRE_BUILD does not support file dependencies! + const std::vector no_output; + const std::vector no_deps; + cmCustomCommand cc(makefile, no_output, autogenProvides, no_deps, commandLines, autogenComment.c_str(), workingDirectory.c_str()); cc.SetEscapeOldStyle(false); cc.SetEscapeAllowMakeVars(true); target->Target->AddPreBuildCommand(cc); + } else { - // Add additional target dependencies to the origin target - for (std::vector::const_iterator - itC = autogenDependTargets.begin(), - itE = autogenDependTargets.end(); - itC != itE; ++itC) { - target->Target->AddUtility(*itC); + // Convert file dependencies std::set to std::vector + std::vector autogenDepends(autogenDependFiles.begin(), + autogenDependFiles.end()); + + // Add link library target dependencies to the autogen target dependencies + for (std::string const& config : configsList) { + cmLinkImplementationLibraries const* libs = + target->GetLinkImplementationLibraries(config); + if (libs != nullptr) { + for (cmLinkItem const& item : libs->Libraries) { + cmGeneratorTarget const* libTarget = item.Target; + if ((libTarget != nullptr) && + !StaticLibraryCycle(target, libTarget, config)) { + std::string util; + if (configsList.size() > 1) { + util += "$<$GetName(); + if (configsList.size() > 1) { + util += ">"; + } + autogenDepends.push_back(util); + } + } + } } - } else -#endif - { + + // Create autogen target cmTarget* autogenTarget = makefile->AddUtilityCommand( autogenTargetName, true, workingDirectory.c_str(), - /*byproducts=*/autogenProvides, autogenDependFiles, commandLines, false, + /*byproducts=*/autogenProvides, autogenDepends, commandLines, false, autogenComment.c_str()); + // Create autogen generator target + localGen->AddGeneratorTarget( + new cmGeneratorTarget(autogenTarget, localGen)); - cmGeneratorTarget* gt = new cmGeneratorTarget(autogenTarget, lg); - lg->AddGeneratorTarget(gt); + // Forward origin utilities to autogen target + for (std::string const& depName : target->Target->GetUtilities()) { + autogenTarget->AddUtility(depName, makefile); + } + // Add additional autogen target dependencies to autogen target + for (cmTarget* depTarget : autogenDependTargets) { + autogenTarget->AddUtility(depTarget->GetName(), makefile); + } - // Add origin link library targets to the autogen target dependencies + // Set FOLDER property in autogen target { - const cmTarget::LinkLibraryVectorType& libVec = - target->Target->GetOriginalLinkLibraries(); - for (cmTarget::LinkLibraryVectorType::const_iterator - itC = libVec.begin(), - itE = libVec.end(); - itC != itE; ++itC) { - const std::string& libName = itC->first; - if (makefile->FindTargetToUse(libName) != CM_NULLPTR) { - autogenDependTargets.push_back(libName); - } + const char* autogenFolder = + makefile->GetState()->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER"); + if (autogenFolder == nullptr) { + autogenFolder = + makefile->GetState()->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER"); } - } - // Add origin utility targets to the autogen target dependencies - { - const std::set& utils = target->Target->GetUtilities(); - for (std::set::const_iterator itC = utils.begin(), - itE = utils.end(); - itC != itE; ++itC) { - autogenDependTargets.push_back(*itC); + // Inherit FOLDER property from target (#13688) + if (autogenFolder == nullptr) { + autogenFolder = SafeString(target->Target->GetProperty("FOLDER")); + } + if ((autogenFolder != nullptr) && (*autogenFolder != '\0')) { + autogenTarget->SetProperty("FOLDER", autogenFolder); } - } - // Add additional target dependencies to the autogen target - for (std::vector::const_iterator - itC = autogenDependTargets.begin(), - itE = autogenDependTargets.end(); - itC != itE; ++itC) { - autogenTarget->AddUtility(*itC); - } - - // Set target folder - const char* autogenFolder = - makefile->GetState()->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER"); - if (!autogenFolder) { - autogenFolder = - makefile->GetState()->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER"); - } - if (autogenFolder && *autogenFolder) { - autogenTarget->SetProperty("FOLDER", autogenFolder); - } else { - // inherit FOLDER property from target (#13688) - utilCopyTargetProperty(gt->Target, target->Target, "FOLDER"); } - target->Target->AddUtility(autogenTargetName); + // Add autogen target to the origin target dependencies + target->Target->AddUtility(autogenTargetName, makefile); } } void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( - cmGeneratorTarget const* target) + cmQtAutoGenDigest const& digest) { + cmGeneratorTarget const* target = digest.Target; cmMakefile* makefile = target->Target->GetMakefile(); + cmQtAutoGen::MultiConfig const multiConfig = + AutogenMultiConfig(target->GetGlobalGenerator()); // forget the variables added here afterwards again: cmMakefile::ScopePushPop varScope(makefile); static_cast(varScope); - // Get configurations - std::string config; - const std::vector configs(GetConfigurations(makefile, &config)); - - // Configurations settings buffers - std::map configSuffix; - std::map configMocIncludes; - std::map configMocDefines; - std::map configUicOptions; - - // Configuration suffix - if (IsMultiConfig(target->GetGlobalGenerator())) { - for (std::vector::const_iterator it = configs.begin(); - it != configs.end(); ++it) { - configSuffix[*it] = "_" + *it; + // Configurations + std::string configDefault; + std::vector configsList; + std::map configSuffixes; + { + configDefault = makefile->GetConfigurations(configsList); + if (configsList.empty()) { + configsList.push_back(""); } } + for (std::string const& cfg : configsList) { + configSuffixes[cfg] = "_" + cfg; + } + + // Configurations settings buffers + cmQtAutoGenSetup setup; // Basic setup + AddDefinitionEscaped(makefile, "_multi_config", + cmQtAutoGen::MultiConfigName(multiConfig)); + AddDefinitionEscaped(makefile, "_build_dir", + GetAutogenTargetBuildDir(target)); + AddDefinitionEscaped(makefile, "_sources", digest.Sources); + AddDefinitionEscaped(makefile, "_headers", digest.Headers); + AddDefinitionEscaped(makefile, "_qt_version_major", digest.QtVersionMajor); + AddDefinitionEscaped(makefile, "_qt_version_minor", digest.QtVersionMinor); { - const bool mocEnabled = target->GetPropertyAsBool("AUTOMOC"); - const bool uicEnabled = target->GetPropertyAsBool("AUTOUIC"); - const bool rccEnabled = target->GetPropertyAsBool("AUTORCC"); - const std::string autogenTargetName = GetAutogenTargetName(target); - const std::string qtMajorVersion = GetQtMajorVersion(target); - - std::vector sources; - std::vector headers; - - if (mocEnabled || uicEnabled || rccEnabled) { - std::vector mocSkipList; - std::vector uicSkipList; - AcquireScanFiles(target, sources, headers, mocSkipList, uicSkipList); - if (mocEnabled) { - MocSetupAutoTarget(target, autogenTargetName, qtMajorVersion, config, - configs, mocSkipList, configMocIncludes, - configMocDefines); - } - if (uicEnabled) { - UicSetupAutoTarget(target, qtMajorVersion, config, configs, - uicSkipList, configUicOptions); + if (digest.MocEnabled || digest.UicEnabled) { + SetupAcquireSkipFiles(digest, setup); + if (digest.MocEnabled) { + SetupAutoTargetMoc(digest, configDefault, configsList, setup); } - if (rccEnabled) { - RccSetupAutoTarget(target, qtMajorVersion); + if (digest.UicEnabled) { + SetupAutoTargetUic(digest, configDefault, configsList, setup); } } - - AddDefinitionEscaped(makefile, "_autogen_build_dir", - GetAutogenTargetBuildDir(target)); - AddDefinitionEscaped(makefile, "_qt_version_major", qtMajorVersion); - AddDefinitionEscaped(makefile, "_sources", sources); - AddDefinitionEscaped(makefile, "_headers", headers); + if (digest.RccEnabled) { + SetupAutoTargetRcc(digest); + } } // Generate info file - std::string infoFile = GetAutogenTargetFilesDir(target); - infoFile += "/AutogenInfo.cmake"; { - std::string inf = cmSystemTools::GetCMakeRoot(); - inf += "/Modules/AutogenInfo.cmake.in"; - makefile->ConfigureFile(inf.c_str(), infoFile.c_str(), false, true, false); - } + std::string const infoDir = GetAutogenTargetFilesDir(target); + if (!cmSystemTools::MakeDirectory(infoDir)) { + std::string emsg = ("Could not create directory: "); + emsg += cmQtAutoGen::Quoted(infoDir); + cmSystemTools::Error(emsg.c_str()); + } + std::string const infoFile = infoDir + "/AutogenInfo.cmake"; + { + std::string infoFileIn = cmSystemTools::GetCMakeRoot(); + infoFileIn += "/Modules/AutogenInfo.cmake.in"; + makefile->ConfigureFile(infoFileIn.c_str(), infoFile.c_str(), false, + true, false); + } - // Append custom definitions to info file on demand - if (!configSuffix.empty() || !configMocDefines.empty() || - !configMocIncludes.empty() || !configUicOptions.empty()) { + // Append custom definitions to info file + // -------------------------------------- // Ensure we have write permission in case .in was read-only. mode_t perm = 0; @@ -1091,39 +1202,22 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( // Open and write file cmsys::ofstream ofs(infoFile.c_str(), std::ios::app); if (ofs) { - ofs << "# Configuration specific options\n"; - for (std::map::iterator - it = configSuffix.begin(), - end = configSuffix.end(); - it != end; ++it) { - ofs << "set(AM_CONFIG_SUFFIX_" << it->first << " " << it->second - << ")\n"; - } - for (std::map::iterator - it = configMocDefines.begin(), - end = configMocDefines.end(); - it != end; ++it) { - ofs << "set(AM_MOC_DEFINITIONS_" << it->first << " " << it->second - << ")\n"; - } - for (std::map::iterator - it = configMocIncludes.begin(), - end = configMocIncludes.end(); - it != end; ++it) { - ofs << "set(AM_MOC_INCLUDES_" << it->first << " " << it->second - << ")\n"; - } - for (std::map::iterator - it = configUicOptions.begin(), - end = configUicOptions.end(); - it != end; ++it) { - ofs << "set(AM_UIC_TARGET_OPTIONS_" << it->first << " " << it->second - << ")\n"; - } + auto OfsWriteMap = [&ofs]( + const char* key, std::map const& map) { + for (auto const& item : map) { + ofs << "set(" << key << "_" << item.first << " " + << cmOutputConverter::EscapeForCMake(item.second) << ")\n"; + } + }; + ofs << "# Configurations options\n"; + OfsWriteMap("AM_CONFIG_SUFFIX", configSuffixes); + OfsWriteMap("AM_MOC_DEFINITIONS", setup.ConfigMocDefines); + OfsWriteMap("AM_MOC_INCLUDES", setup.ConfigMocIncludes); + OfsWriteMap("AM_UIC_TARGET_OPTIONS", setup.ConfigUicOptions); } else { // File open error std::string error = "Internal CMake error when trying to open file: "; - error += cmQtAutoGeneratorCommon::Quoted(infoFile); + error += cmQtAutoGen::Quoted(infoFile); error += " for writing."; cmSystemTools::Error(error.c_str()); } diff --git a/Source/cmQtAutoGeneratorInitializer.h b/Source/cmQtAutoGeneratorInitializer.h index ca806f5a9..b8a5ae480 100644 --- a/Source/cmQtAutoGeneratorInitializer.h +++ b/Source/cmQtAutoGeneratorInitializer.h @@ -4,17 +4,21 @@ #define cmQtAutoGeneratorInitializer_h #include "cmConfigure.h" // IWYU pragma: keep +#include "cmQtAutoGenDigest.h" + +#include class cmGeneratorTarget; -class cmLocalGenerator; class cmQtAutoGeneratorInitializer { public: - static void InitializeAutogenSources(cmGeneratorTarget* target); - static void InitializeAutogenTarget(cmLocalGenerator* lg, - cmGeneratorTarget* target); - static void SetupAutoGenerateTarget(cmGeneratorTarget const* target); + static std::string GetQtMajorVersion(cmGeneratorTarget const* target); + static std::string GetQtMinorVersion(cmGeneratorTarget const* target, + std::string const& qtVersionMajor); + + static void InitializeAutogenTarget(cmQtAutoGenDigest& digest); + static void SetupAutoGenerateTarget(cmQtAutoGenDigest const& digest); }; #endif diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index c3ecb51b8..b329d3828 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -1,16 +1,15 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmQtAutoGen.h" #include "cmQtAutoGenerators.h" -#include "cmQtAutoGeneratorCommon.h" -#include "cmConfigure.h" #include "cmsys/FStream.hxx" #include "cmsys/Terminal.h" #include -#include +#include #include +#include #include -#include #include #include @@ -23,7 +22,6 @@ #include "cmStateDirectory.h" #include "cmStateSnapshot.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(__APPLE__) @@ -38,253 +36,119 @@ static const char* SettingsKeyRcc = "AM_RCC_SETTINGS_HASH"; // -- Static functions -inline static std::string Quoted(const std::string& text) +static std::string HeadLine(std::string const& title) { - return cmQtAutoGeneratorCommon::Quoted(text); + std::string head = title; + head += '\n'; + head.append(head.size() - 1, '-'); + head += '\n'; + return head; } -static std::string QuotedCommand(const std::vector& command) +static std::string QuotedCommand(std::vector const& command) { std::string res; - for (std::vector::const_iterator cit = command.begin(); - cit != command.end(); ++cit) { + for (std::string const& item : command) { if (!res.empty()) { res.push_back(' '); } - const std::string cesc = Quoted(*cit); - if (cit->empty() || (cesc.size() > (cit->size() + 2)) || + std::string const cesc = cmQtAutoGen::Quoted(item); + if (item.empty() || (cesc.size() > (item.size() + 2)) || (cesc.find(' ') != std::string::npos)) { res += cesc; } else { - res += *cit; + res += item; } } return res; } -static void InfoGet(cmMakefile* makefile, const char* key, std::string& value) +static std::string SubDirPrefix(std::string const& fileName) { - value = makefile->GetSafeDefinition(key); -} - -static void InfoGet(cmMakefile* makefile, const char* key, bool& value) -{ - value = makefile->IsOn(key); -} - -static void InfoGet(cmMakefile* makefile, const char* key, - std::vector& list) -{ - cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition(key), list); -} - -static void InfoGetConfig(cmMakefile* makefile, const char* key, - const std::string& config, std::string& value) -{ - const char* valueConf = CM_NULLPTR; - { - std::string keyConf = key; - if (!config.empty()) { - keyConf += "_"; - keyConf += config; - } - valueConf = makefile->GetDefinition(keyConf); - } - if (valueConf == CM_NULLPTR) { - valueConf = makefile->GetSafeDefinition(key); - } - value = valueConf; -} - -static void InfoGetConfig(cmMakefile* makefile, const char* key, - const std::string& config, - std::vector& list) -{ - std::string value; - InfoGetConfig(makefile, key, config, value); - cmSystemTools::ExpandListArgument(value, list); -} - -inline static bool SettingsMatch(cmMakefile* makefile, const char* key, - const std::string& value) -{ - return (value == makefile->GetSafeDefinition(key)); -} - -static void SettingAppend(std::string& str, const char* key, - const std::string& value) -{ - if (!value.empty()) { - str += "set("; - str += key; - str += " "; - str += cmOutputConverter::EscapeForCMake(value); - str += ")\n"; - } -} - -static std::string SubDirPrefix(const std::string& fileName) -{ - std::string res(cmsys::SystemTools::GetFilenamePath(fileName)); + std::string res(cmSystemTools::GetFilenamePath(fileName)); if (!res.empty()) { res += '/'; } return res; } -static bool FileNameIsUnique(const std::string& filePath, - const std::map& fileMap) -{ - size_t count(0); - const std::string fileName = cmsys::SystemTools::GetFilenameName(filePath); - for (std::map::const_iterator si = fileMap.begin(); - si != fileMap.end(); ++si) { - if (cmsys::SystemTools::GetFilenameName(si->first) == fileName) { - ++count; - if (count > 1) { - return false; - } - } - } - return true; -} - -static bool ReadAll(std::string& content, const std::string& filename) +static bool ReadFile(std::string& content, std::string const& filename, + std::string* error = nullptr) { bool success = false; - { - cmsys::ifstream ifs(filename.c_str()); + if (cmSystemTools::FileExists(filename)) { + std::size_t const length = cmSystemTools::FileLength(filename); + cmsys::ifstream ifs(filename.c_str(), (std::ios::in | std::ios::binary)); if (ifs) { - std::ostringstream osst; - osst << ifs.rdbuf(); - content = osst.str(); - success = true; + content.resize(length); + ifs.read(&content.front(), content.size()); + if (ifs) { + success = true; + } else { + content.clear(); + if (error != nullptr) { + error->append("Reading from the file failed."); + } + } + } else if (error != nullptr) { + error->append("Opening the file for reading failed."); } + } else if (error != nullptr) { + error->append("The file does not exist."); } return success; } /** - * @brief Tests if buildFile doesn't exist or is older than sourceFile - * @return True if buildFile doesn't exist or is older than sourceFile + * @brief Tests if buildFile is older than sourceFile + * @return True if buildFile is older than sourceFile. + * False may indicate an error. */ -static bool FileAbsentOrOlder(const std::string& buildFile, - const std::string& sourceFile) +static bool FileIsOlderThan(std::string const& buildFile, + std::string const& sourceFile, + std::string* error = nullptr) { int result = 0; - bool success = - cmsys::SystemTools::FileTimeCompare(buildFile, sourceFile, &result); - return (!success || (result <= 0)); -} - -static bool ListContains(const std::vector& list, - const std::string& entry) -{ - return (std::find(list.begin(), list.end(), entry) != list.end()); -} - -static std::string JoinOptionsList(const std::vector& opts) -{ - return cmOutputConverter::EscapeForCMake(cmJoin(opts, ";")); -} - -static std::string JoinOptionsMap( - const std::map& opts) -{ - std::string result; - for (std::map::const_iterator it = opts.begin(); - it != opts.end(); ++it) { - if (it != opts.begin()) { - result += cmQtAutoGeneratorCommon::listSep; - } - result += it->first; - result += "==="; - result += it->second; + if (cmSystemTools::FileTimeCompare(buildFile, sourceFile, &result)) { + return (result < 0); } - return result; -} - -static std::string JoinExts(const std::vector& lst) -{ - std::string result; - if (!lst.empty()) { - const std::string separator = ","; - for (std::vector::const_iterator it = lst.begin(); - it != lst.end(); ++it) { - if (it != lst.begin()) { - result += separator; - } - result += '.'; - result += *it; - } + if (error != nullptr) { + error->append( + "File modification time comparison failed for the files\n "); + error->append(cmQtAutoGen::Quoted(buildFile)); + error->append("\nand\n "); + error->append(cmQtAutoGen::Quoted(sourceFile)); } - return result; + return false; } -static void UicMergeOptions(std::vector& opts, - const std::vector& fileOpts, - bool isQt5) +static bool ListContains(std::vector const& list, + std::string const& entry) { - static const char* valueOptions[] = { "tr", "translate", - "postfix", "generator", - "include", // Since Qt 5.3 - "g" }; - std::vector extraOpts; - for (std::vector::const_iterator it = fileOpts.begin(); - it != fileOpts.end(); ++it) { - std::vector::iterator existingIt = - std::find(opts.begin(), opts.end(), *it); - if (existingIt != opts.end()) { - const char* o = it->c_str(); - if (*o == '-') { - ++o; - } - if (isQt5 && *o == '-') { - ++o; - } - if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions), - cmStrCmp(*it)) != cmArrayEnd(valueOptions)) { - assert(existingIt + 1 != opts.end()); - *(existingIt + 1) = *(it + 1); - ++it; - } - } else { - extraOpts.push_back(*it); - } - } - opts.insert(opts.end(), extraOpts.begin(), extraOpts.end()); + return (std::find(list.begin(), list.end(), entry) != list.end()); } // -- Class methods cmQtAutoGenerators::cmQtAutoGenerators() - : Verbose(cmsys::SystemTools::HasEnv("VERBOSE")) + : MultiConfig(cmQtAutoGen::WRAP) + , IncludeProjectDirsBefore(false) + , Verbose(cmSystemTools::HasEnv("VERBOSE")) , ColorOutput(true) , MocSettingsChanged(false) , MocPredefsChanged(false) - , MocRunFailed(false) + , MocRelaxedMode(false) , UicSettingsChanged(false) - , UicRunFailed(false) , RccSettingsChanged(false) - , RccRunFailed(false) { - - std::string colorEnv; - cmsys::SystemTools::GetEnv("COLOR", colorEnv); - if (!colorEnv.empty()) { - if (cmSystemTools::IsOn(colorEnv.c_str())) { - this->ColorOutput = true; - } else { - this->ColorOutput = false; + { + std::string colorEnv; + cmSystemTools::GetEnv("COLOR", colorEnv); + if (!colorEnv.empty()) { + this->ColorOutput = cmSystemTools::IsOn(colorEnv.c_str()); } } - // Moc macro filters - this->MocMacroFilters[0].first = "Q_OBJECT"; - this->MocMacroFilters[0].second.compile("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]"); - this->MocMacroFilters[1].first = "Q_GADGET"; - this->MocMacroFilters[1].second.compile("[\n][ \t]*Q_GADGET[^a-zA-Z0-9_]"); - // Precompile regular expressions this->MocRegExpInclude.compile( "[\n][ \t]*#[ \t]*include[ \t]+" @@ -293,8 +157,8 @@ cmQtAutoGenerators::cmQtAutoGenerators() "[\"<](([^ \">]+/)?ui_[^ \">/]+\\.h)[\">]"); } -bool cmQtAutoGenerators::Run(const std::string& targetDirectory, - const std::string& config) +bool cmQtAutoGenerators::Run(std::string const& targetDirectory, + std::string const& config) { cmake cm(cmake::RoleScript); cm.SetHomeOutputDirectory(targetDirectory); @@ -306,16 +170,14 @@ bool cmQtAutoGenerators::Run(const std::string& targetDirectory, snapshot.GetDirectory().SetCurrentBinary(targetDirectory); snapshot.GetDirectory().SetCurrentSource(targetDirectory); - CM_AUTO_PTR mf(new cmMakefile(&gg, snapshot)); - gg.SetCurrentMakefile(mf.get()); + auto makefile = cm::make_unique(&gg, snapshot); + gg.SetCurrentMakefile(makefile.get()); bool success = false; - if (this->ReadAutogenInfoFile(mf.get(), targetDirectory, config)) { - // Read old settings - this->SettingsFileRead(mf.get()); - // Init and run - this->Init(mf.get()); - if (this->RunAutogen()) { + if (this->InitInfoFile(makefile.get(), targetDirectory, config)) { + // Read latest settings + this->SettingsFileRead(makefile.get()); + if (this->Process()) { // Write current settings if (this->SettingsFileWrite()) { success = true; @@ -325,108 +187,145 @@ bool cmQtAutoGenerators::Run(const std::string& targetDirectory, return success; } -bool cmQtAutoGenerators::MocDependFilterPush(const std::string& key, - const std::string& regExp) +bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile, + std::string const& targetDirectory, + std::string const& config) { - bool success = false; - if (!key.empty()) { - if (!regExp.empty()) { - MocDependFilter filter; - filter.key = key; - if (filter.regExp.compile(regExp)) { - this->MocDependFilters.push_back(filter); - success = true; - } else { - this->LogError("AutoMoc: Error in AUTOMOC_DEPEND_FILTERS: Compiling " - "regular expression failed.\nKey: " + - Quoted(key) + "\nExp.: " + Quoted(regExp)); + // -- Meta + this->HeaderExtensions = makefile->GetCMakeInstance()->GetHeaderExtensions(); + + // Utility lambdas + auto InfoGet = [makefile](const char* key) { + return makefile->GetSafeDefinition(key); + }; + auto InfoGetBool = [makefile](const char* key) { + return makefile->IsOn(key); + }; + auto InfoGetList = [makefile](const char* key) -> std::vector { + std::vector list; + cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition(key), list); + return list; + }; + auto InfoGetLists = + [makefile](const char* key) -> std::vector> { + std::vector> lists; + { + std::string const value = makefile->GetSafeDefinition(key); + std::string::size_type pos = 0; + while (pos < value.size()) { + std::string::size_type next = value.find(cmQtAutoGen::listSep, pos); + std::string::size_type length = + (next != std::string::npos) ? next - pos : value.size() - pos; + // Remove enclosing braces + if (length >= 2) { + std::string::const_iterator itBeg = value.begin() + (pos + 1); + std::string::const_iterator itEnd = itBeg + (length - 2); + { + std::string subValue(itBeg, itEnd); + std::vector list; + cmSystemTools::ExpandListArgument(subValue, list); + lists.push_back(std::move(list)); + } + } + pos += length; + pos += cmQtAutoGen::listSep.size(); } - } else { - this->LogError("AutoMoc: Error in AUTOMOC_DEPEND_FILTERS: Regular " - "expression is empty"); } - } else { - this->LogError("AutoMoc: Error in AUTOMOC_DEPEND_FILTERS: Key is empty"); - } - return success; -} - -bool cmQtAutoGenerators::ReadAutogenInfoFile( - cmMakefile* makefile, const std::string& targetDirectory, - const std::string& config) -{ - std::string filename(cmSystemTools::CollapseFullPath(targetDirectory)); - cmSystemTools::ConvertToUnixSlashes(filename); - filename += "/AutogenInfo.cmake"; + return lists; + }; + auto InfoGetConfig = [makefile, &config](const char* key) -> std::string { + const char* valueConf = nullptr; + { + std::string keyConf = key; + keyConf += '_'; + keyConf += config; + valueConf = makefile->GetDefinition(keyConf); + } + if (valueConf == nullptr) { + valueConf = makefile->GetSafeDefinition(key); + } + return std::string(valueConf); + }; + auto InfoGetConfigList = + [&InfoGetConfig](const char* key) -> std::vector { + std::vector list; + cmSystemTools::ExpandListArgument(InfoGetConfig(key), list); + return list; + }; - if (!makefile->ReadListFile(filename.c_str())) { - this->LogError("AutoGen: Error processing file: " + filename); + // -- Read info file + this->InfoFile = cmSystemTools::CollapseFullPath(targetDirectory); + cmSystemTools::ConvertToUnixSlashes(this->InfoFile); + this->InfoFile += "/AutogenInfo.cmake"; + if (!makefile->ReadListFile(this->InfoFile.c_str())) { + this->LogFileError(cmQtAutoGen::GEN, this->InfoFile, + "File processing failed"); return false; } - // - Old settings file - { - this->SettingsFile = cmSystemTools::CollapseFullPath(targetDirectory); - cmSystemTools::ConvertToUnixSlashes(this->SettingsFile); - this->SettingsFile += "/AutogenOldSettings"; - this->SettingsFile += this->ConfigSuffix; - this->SettingsFile += ".cmake"; - } - // -- Meta - InfoGetConfig(makefile, "AM_CONFIG_SUFFIX", config, this->ConfigSuffix); + this->MultiConfig = cmQtAutoGen::MultiConfigType(InfoGet("AM_MULTI_CONFIG")); + this->ConfigSuffix = InfoGetConfig("AM_CONFIG_SUFFIX"); + if (this->ConfigSuffix.empty()) { + this->ConfigSuffix = "_"; + this->ConfigSuffix += config; + } // - Files and directories - InfoGet(makefile, "AM_CMAKE_SOURCE_DIR", this->ProjectSourceDir); - InfoGet(makefile, "AM_CMAKE_BINARY_DIR", this->ProjectBinaryDir); - InfoGet(makefile, "AM_CMAKE_CURRENT_SOURCE_DIR", this->CurrentSourceDir); - InfoGet(makefile, "AM_CMAKE_CURRENT_BINARY_DIR", this->CurrentBinaryDir); - InfoGet(makefile, "AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE", - this->IncludeProjectDirsBefore); - InfoGet(makefile, "AM_BUILD_DIR", this->AutogenBuildDir); + this->ProjectSourceDir = InfoGet("AM_CMAKE_SOURCE_DIR"); + this->ProjectBinaryDir = InfoGet("AM_CMAKE_BINARY_DIR"); + this->CurrentSourceDir = InfoGet("AM_CMAKE_CURRENT_SOURCE_DIR"); + this->CurrentBinaryDir = InfoGet("AM_CMAKE_CURRENT_BINARY_DIR"); + this->IncludeProjectDirsBefore = + InfoGetBool("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"); + this->AutogenBuildDir = InfoGet("AM_BUILD_DIR"); if (this->AutogenBuildDir.empty()) { - this->LogError("AutoGen: Error: Missing autogen build directory "); + this->LogFileError(cmQtAutoGen::GEN, this->InfoFile, + "Autogen build directory missing"); return false; } - InfoGet(makefile, "AM_SOURCES", this->Sources); - InfoGet(makefile, "AM_HEADERS", this->Headers); // - Qt environment - InfoGet(makefile, "AM_QT_VERSION_MAJOR", this->QtMajorVersion); - if (this->QtMajorVersion.empty()) { - InfoGet(makefile, "AM_Qt5Core_VERSION_MAJOR", this->QtMajorVersion); - } - InfoGet(makefile, "AM_QT_MOC_EXECUTABLE", this->MocExecutable); - InfoGet(makefile, "AM_QT_UIC_EXECUTABLE", this->UicExecutable); - InfoGet(makefile, "AM_QT_RCC_EXECUTABLE", this->RccExecutable); + this->QtMajorVersion = InfoGet("AM_QT_VERSION_MAJOR"); + this->QtMinorVersion = InfoGet("AM_QT_VERSION_MINOR"); + this->MocExecutable = InfoGet("AM_QT_MOC_EXECUTABLE"); + this->UicExecutable = InfoGet("AM_QT_UIC_EXECUTABLE"); + this->RccExecutable = InfoGet("AM_QT_RCC_EXECUTABLE"); - InfoGet(makefile, "AM_MOC_PREDEFS_CMD", this->MocPredefsCmd); // Check Qt version if ((this->QtMajorVersion != "4") && (this->QtMajorVersion != "5")) { - this->LogError("AutoGen: Error: Unsupported Qt version: " + - Quoted(this->QtMajorVersion)); + this->LogFileError(cmQtAutoGen::GEN, this->InfoFile, + "Unsupported Qt version: " + + cmQtAutoGen::Quoted(this->QtMajorVersion)); return false; } // - Moc if (this->MocEnabled()) { - InfoGet(makefile, "AM_MOC_SKIP", this->MocSkipList); - InfoGetConfig(makefile, "AM_MOC_DEFINITIONS", config, - this->MocDefinitions); + this->MocSkipList = InfoGetList("AM_MOC_SKIP"); + this->MocDefinitions = InfoGetConfigList("AM_MOC_DEFINITIONS"); #ifdef _WIN32 { - const std::string win32("WIN32"); + std::string const win32("WIN32"); if (!ListContains(this->MocDefinitions, win32)) { this->MocDefinitions.push_back(win32); } } #endif - InfoGetConfig(makefile, "AM_MOC_INCLUDES", config, this->MocIncludePaths); - InfoGet(makefile, "AM_MOC_OPTIONS", this->MocOptions); - InfoGet(makefile, "AM_MOC_RELAXED_MODE", this->MocRelaxedMode); + this->MocIncludePaths = InfoGetConfigList("AM_MOC_INCLUDES"); + this->MocOptions = InfoGetList("AM_MOC_OPTIONS"); + this->MocRelaxedMode = InfoGetBool("AM_MOC_RELAXED_MODE"); { - std::vector mocDependFilters; - InfoGet(makefile, "AM_MOC_DEPEND_FILTERS", mocDependFilters); + std::vector const MocMacroNames = + InfoGetList("AM_MOC_MACRO_NAMES"); + for (std::string const& item : MocMacroNames) { + this->MocMacroFilters.emplace_back( + item, ("[\n][ \t]*{?[ \t]*" + item).append("[^a-zA-Z0-9_]")); + } + } + { + std::vector const mocDependFilters = + InfoGetList("AM_MOC_DEPEND_FILTERS"); // Insert Q_PLUGIN_METADATA dependency filter if (this->QtMajorVersion != "4") { this->MocDependFilterPush("Q_PLUGIN_METADATA", @@ -435,104 +334,266 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( } // Insert user defined dependency filters if ((mocDependFilters.size() % 2) == 0) { - for (std::vector::const_iterator dit = - mocDependFilters.begin(); - dit != mocDependFilters.end(); dit += 2) { + for (std::vector::const_iterator + dit = mocDependFilters.begin(), + ditEnd = mocDependFilters.end(); + dit != ditEnd; dit += 2) { if (!this->MocDependFilterPush(*dit, *(dit + 1))) { return false; } } } else { - this->LogError( - "AutoMoc: Error: AUTOMOC_DEPEND_FILTERS list size is not " - "a multiple of 2 in:\n" + - Quoted(filename)); + this->LogFileError( + cmQtAutoGen::MOC, this->InfoFile, + "AUTOMOC_DEPEND_FILTERS list size is not a multiple of 2"); return false; } } + this->MocPredefsCmd = InfoGetList("AM_MOC_PREDEFS_CMD"); } // - Uic if (this->UicEnabled()) { - InfoGet(makefile, "AM_UIC_SKIP", this->UicSkipList); - InfoGet(makefile, "AM_UIC_SEARCH_PATHS", this->UicSearchPaths); - InfoGetConfig(makefile, "AM_UIC_TARGET_OPTIONS", config, - this->UicTargetOptions); + this->UicSkipList = InfoGetList("AM_UIC_SKIP"); + this->UicSearchPaths = InfoGetList("AM_UIC_SEARCH_PATHS"); + this->UicTargetOptions = InfoGetConfigList("AM_UIC_TARGET_OPTIONS"); { - std::vector uicFilesVec; - std::vector uicOptionsVec; - InfoGet(makefile, "AM_UIC_OPTIONS_FILES", uicFilesVec); - InfoGet(makefile, "AM_UIC_OPTIONS_OPTIONS", uicOptionsVec); + auto sources = InfoGetList("AM_UIC_OPTIONS_FILES"); + auto options = InfoGetLists("AM_UIC_OPTIONS_OPTIONS"); // Compare list sizes - if (uicFilesVec.size() == uicOptionsVec.size()) { - for (std::vector::iterator - fileIt = uicFilesVec.begin(), - optionIt = uicOptionsVec.begin(); - fileIt != uicFilesVec.end(); ++fileIt, ++optionIt) { - cmSystemTools::ReplaceString(*optionIt, - cmQtAutoGeneratorCommon::listSep, ";"); - this->UicOptions[*fileIt] = *optionIt; - } - } else { - this->LogError( - "AutoGen: Error: Uic files/options lists size missmatch in:\n" + - Quoted(filename)); + if (sources.size() != options.size()) { + std::ostringstream ost; + ost << "files/options lists sizes missmatch (" << sources.size() << "/" + << options.size() << ")"; + this->LogFileError(cmQtAutoGen::UIC, this->InfoFile, ost.str()); return false; } + auto fitEnd = sources.cend(); + auto fit = sources.begin(); + auto oit = options.begin(); + while (fit != fitEnd) { + this->UicOptions[*fit] = std::move(*oit); + ++fit; + ++oit; + } } } // - Rcc if (this->RccEnabled()) { - InfoGet(makefile, "AM_RCC_SOURCES", this->RccSources); - // File options + // File lists + auto sources = InfoGetList("AM_RCC_SOURCES"); + auto builds = InfoGetList("AM_RCC_BUILDS"); + auto options = InfoGetLists("AM_RCC_OPTIONS"); + auto inputs = InfoGetLists("AM_RCC_INPUTS"); + + if (sources.size() != builds.size()) { + std::ostringstream ost; + ost << "sources, builds lists sizes missmatch (" << sources.size() << "/" + << builds.size() << ")"; + this->LogFileError(cmQtAutoGen::RCC, this->InfoFile, ost.str()); + return false; + } + if (sources.size() != options.size()) { + std::ostringstream ost; + ost << "sources, options lists sizes missmatch (" << sources.size() + << "/" << options.size() << ")"; + this->LogFileError(cmQtAutoGen::RCC, this->InfoFile, ost.str()); + return false; + } + if (sources.size() != inputs.size()) { + std::ostringstream ost; + ost << "sources, inputs lists sizes missmatch (" << sources.size() << "/" + << inputs.size() << ")"; + this->LogFileError(cmQtAutoGen::RCC, this->InfoFile, ost.str()); + return false; + } + { + auto srcItEnd = sources.end(); + auto srcIt = sources.begin(); + auto bldIt = builds.begin(); + auto optIt = options.begin(); + auto inpIt = inputs.begin(); + while (srcIt != srcItEnd) { + this->RccJobs.push_back(RccJob{ std::move(*srcIt), std::move(*bldIt), + std::move(*optIt), + std::move(*inpIt) }); + ++srcIt; + ++bldIt; + ++optIt; + ++inpIt; + } + } + } + + // Initialize source file jobs + { + // Utility lambdas + auto AddJob = [this](std::map& jobs, + std::string&& sourceFile) { + const bool moc = !this->MocSkip(sourceFile); + const bool uic = !this->UicSkip(sourceFile); + if (moc || uic) { + SourceJob& job = jobs[std::move(sourceFile)]; + job.Moc = moc; + job.Uic = uic; + } + }; + + // Add header jobs + for (std::string& hdr : InfoGetList("AM_HEADERS")) { + AddJob(this->HeaderJobs, std::move(hdr)); + } + // Add source jobs { - std::vector rccFilesVec; - std::vector rccOptionsVec; - InfoGet(makefile, "AM_RCC_OPTIONS_FILES", rccFilesVec); - InfoGet(makefile, "AM_RCC_OPTIONS_OPTIONS", rccOptionsVec); - if (rccFilesVec.size() == rccOptionsVec.size()) { - for (std::vector::iterator - fileIt = rccFilesVec.begin(), - optionIt = rccOptionsVec.begin(); - fileIt != rccFilesVec.end(); ++fileIt, ++optionIt) { - // Replace item separator - cmSystemTools::ReplaceString(*optionIt, - cmQtAutoGeneratorCommon::listSep, ";"); - this->RccOptions[*fileIt] = *optionIt; + std::vector sources = InfoGetList("AM_SOURCES"); + // Add header(s) for the source file + for (std::string const& src : sources) { + const bool srcMoc = !this->MocSkip(src); + const bool srcUic = !this->UicSkip(src); + if (!srcMoc && !srcUic) { + continue; } - } else { - this->LogError( - "AutoGen: Error: RCC files/options lists size missmatch in:\n" + - Quoted(filename)); - return false; + // Search for the default header file and a private header + std::array headerBases; + headerBases[0] = SubDirPrefix(src); + headerBases[0] += cmSystemTools::GetFilenameWithoutLastExtension(src); + headerBases[1] = headerBases[0]; + headerBases[1] += "_p"; + for (std::string const& headerBase : headerBases) { + std::string header; + if (this->FindHeader(header, headerBase)) { + const bool moc = srcMoc && !this->MocSkip(header); + const bool uic = srcUic && !this->UicSkip(header); + if (moc || uic) { + SourceJob& job = this->HeaderJobs[std::move(header)]; + job.Moc = moc; + job.Uic = uic; + } + } + } + } + // Add Source jobs + for (std::string& src : sources) { + AddJob(this->SourceJobs, std::move(src)); } } - // File lists + } + + // Init derived information + // ------------------------ + + // Init file path checksum generator + this->FilePathChecksum.setupParentDirs( + this->CurrentSourceDir, this->CurrentBinaryDir, this->ProjectSourceDir, + this->ProjectBinaryDir); + + // include directory + this->AutogenIncludeDir = "include"; + if (this->MultiConfig != cmQtAutoGen::SINGLE) { + this->AutogenIncludeDir += this->ConfigSuffix; + } + this->AutogenIncludeDir += "/"; + + // Moc variables + if (this->MocEnabled()) { + // Mocs compilation file + this->MocCompFileRel = "mocs_compilation"; + if (this->MultiConfig == cmQtAutoGen::FULL) { + this->MocCompFileRel += this->ConfigSuffix; + } + this->MocCompFileRel += ".cpp"; + this->MocCompFileAbs = cmSystemTools::CollapseCombinedPath( + this->AutogenBuildDir, this->MocCompFileRel); + + // Moc predefs file + if (!this->MocPredefsCmd.empty()) { + this->MocPredefsFileRel = "moc_predefs"; + if (this->MultiConfig != cmQtAutoGen::SINGLE) { + this->MocPredefsFileRel += this->ConfigSuffix; + } + this->MocPredefsFileRel += ".h"; + this->MocPredefsFileAbs = cmSystemTools::CollapseCombinedPath( + this->AutogenBuildDir, this->MocPredefsFileRel); + } + + // Sort include directories on demand + if (this->IncludeProjectDirsBefore) { + // Move strings to temporary list + std::list includes; + includes.insert(includes.end(), this->MocIncludePaths.begin(), + this->MocIncludePaths.end()); + this->MocIncludePaths.clear(); + this->MocIncludePaths.reserve(includes.size()); + // Append project directories only + { + std::array const movePaths = { + { &this->ProjectBinaryDir, &this->ProjectSourceDir } + }; + for (std::string const* ppath : movePaths) { + std::list::iterator it = includes.begin(); + while (it != includes.end()) { + std::string const& path = *it; + if (cmSystemTools::StringStartsWith(path, ppath->c_str())) { + this->MocIncludePaths.push_back(path); + it = includes.erase(it); + } else { + ++it; + } + } + } + } + // Append remaining directories + this->MocIncludePaths.insert(this->MocIncludePaths.end(), + includes.begin(), includes.end()); + } + // Compose moc includes list { - std::vector rccInputLists; - InfoGet(makefile, "AM_RCC_INPUTS", rccInputLists); - if (this->RccSources.size() == rccInputLists.size()) { - for (std::vector::iterator - fileIt = this->RccSources.begin(), - inputIt = rccInputLists.begin(); - fileIt != this->RccSources.end(); ++fileIt, ++inputIt) { - // Remove braces - *inputIt = inputIt->substr(1, inputIt->size() - 2); - // Replace item separator - cmSystemTools::ReplaceString(*inputIt, - cmQtAutoGeneratorCommon::listSep, ";"); - std::vector rccInputFiles; - cmSystemTools::ExpandListArgument(*inputIt, rccInputFiles); - this->RccInputs[*fileIt] = rccInputFiles; + std::set frameworkPaths; + for (std::string const& path : this->MocIncludePaths) { + this->MocIncludes.push_back("-I" + path); + // Extract framework path + if (cmHasLiteralSuffix(path, ".framework/Headers")) { + // Go up twice to get to the framework root + std::vector pathComponents; + cmSystemTools::SplitPath(path, pathComponents); + std::string frameworkPath = cmSystemTools::JoinPath( + pathComponents.begin(), pathComponents.end() - 2); + frameworkPaths.insert(frameworkPath); } - } else { - this->LogError( - "AutoGen: Error: RCC sources/inputs lists size missmatch in:\n" + - Quoted(filename)); - return false; } + // Append framework includes + for (std::string const& path : frameworkPaths) { + this->MocIncludes.push_back("-F"); + this->MocIncludes.push_back(path); + } + } + // Setup single list with all options + { + // Add includes + this->MocAllOptions.insert(this->MocAllOptions.end(), + this->MocIncludes.begin(), + this->MocIncludes.end()); + // Add definitions + for (std::string const& def : this->MocDefinitions) { + this->MocAllOptions.push_back("-D" + def); + } + // Add options + this->MocAllOptions.insert(this->MocAllOptions.end(), + this->MocOptions.begin(), + this->MocOptions.end()); + } + } + + // - Old settings file + { + this->SettingsFile = cmSystemTools::CollapseFullPath(targetDirectory); + cmSystemTools::ConvertToUnixSlashes(this->SettingsFile); + this->SettingsFile += "/AutogenOldSettings"; + if (this->MultiConfig != cmQtAutoGen::SINGLE) { + this->SettingsFile += this->ConfigSuffix; } + this->SettingsFile += ".cmake"; } return true; @@ -543,20 +604,16 @@ void cmQtAutoGenerators::SettingsFileRead(cmMakefile* makefile) // Compose current settings strings { cmCryptoHash crypt(cmCryptoHash::AlgoSHA256); - const std::string sep(" ~~~ "); + std::string const sep(" ~~~ "); if (this->MocEnabled()) { std::string str; str += this->MocExecutable; str += sep; - str += JoinOptionsList(this->MocDefinitions); - str += sep; - str += JoinOptionsList(this->MocIncludePaths); - str += sep; - str += JoinOptionsList(this->MocOptions); + str += cmJoin(this->MocAllOptions, ";"); str += sep; str += this->IncludeProjectDirsBefore ? "TRUE" : "FALSE"; str += sep; - str += JoinOptionsList(this->MocPredefsCmd); + str += cmJoin(this->MocPredefsCmd, ";"); str += sep; this->SettingsStringMoc = crypt.HashString(str); } @@ -564,17 +621,27 @@ void cmQtAutoGenerators::SettingsFileRead(cmMakefile* makefile) std::string str; str += this->UicExecutable; str += sep; - str += JoinOptionsList(this->UicTargetOptions); - str += sep; - str += JoinOptionsMap(this->UicOptions); + str += cmJoin(this->UicTargetOptions, ";"); + for (const auto& item : this->UicOptions) { + str += sep; + str += item.first; + str += sep; + str += cmJoin(item.second, ";"); + } str += sep; this->SettingsStringUic = crypt.HashString(str); } if (this->RccEnabled()) { std::string str; str += this->RccExecutable; - str += sep; - str += JoinOptionsMap(this->RccOptions); + for (const RccJob& rccJob : this->RccJobs) { + str += sep; + str += rccJob.QrcFile; + str += sep; + str += rccJob.RccFile; + str += sep; + str += cmJoin(rccJob.Options, ";"); + } str += sep; this->SettingsStringRcc = crypt.HashString(str); } @@ -582,19 +649,24 @@ void cmQtAutoGenerators::SettingsFileRead(cmMakefile* makefile) // Read old settings if (makefile->ReadListFile(this->SettingsFile.c_str())) { - if (!SettingsMatch(makefile, SettingsKeyMoc, this->SettingsStringMoc)) { - this->MocSettingsChanged = true; - } - if (!SettingsMatch(makefile, SettingsKeyUic, this->SettingsStringUic)) { - this->UicSettingsChanged = true; - } - if (!SettingsMatch(makefile, SettingsKeyRcc, this->SettingsStringRcc)) { - this->RccSettingsChanged = true; + { + auto SMatch = [makefile](const char* key, std::string const& value) { + return (value == makefile->GetSafeDefinition(key)); + }; + if (!SMatch(SettingsKeyMoc, this->SettingsStringMoc)) { + this->MocSettingsChanged = true; + } + if (!SMatch(SettingsKeyUic, this->SettingsStringUic)) { + this->UicSettingsChanged = true; + } + if (!SMatch(SettingsKeyRcc, this->SettingsStringRcc)) { + this->RccSettingsChanged = true; + } } // In case any setting changed remove the old settings file. // This triggers a full rebuild on the next run if the current // build is aborted before writing the current settings in the end. - if (this->AnySettingsChanged()) { + if (this->SettingsChanged()) { cmSystemTools::RemoveFile(this->SettingsFile); } } else { @@ -609,20 +681,30 @@ bool cmQtAutoGenerators::SettingsFileWrite() { bool success = true; // Only write if any setting changed - if (this->AnySettingsChanged()) { + if (this->SettingsChanged()) { if (this->Verbose) { - this->LogInfo("AutoGen: Writing settings file " + - Quoted(this->SettingsFile)); + this->LogInfo(cmQtAutoGen::GEN, "Writing settings file " + + cmQtAutoGen::Quoted(this->SettingsFile)); } // Compose settings file content std::string settings; - SettingAppend(settings, SettingsKeyMoc, this->SettingsStringMoc); - SettingAppend(settings, SettingsKeyUic, this->SettingsStringUic); - SettingAppend(settings, SettingsKeyRcc, this->SettingsStringRcc); + { + auto SettingAppend = [&settings](const char* key, + std::string const& value) { + settings += "set("; + settings += key; + settings += " "; + settings += cmOutputConverter::EscapeForCMake(value); + settings += ")\n"; + }; + SettingAppend(SettingsKeyMoc, this->SettingsStringMoc); + SettingAppend(SettingsKeyUic, this->SettingsStringUic); + SettingAppend(SettingsKeyRcc, this->SettingsStringRcc); + } // Write settings file - if (!this->FileWrite("AutoGen", this->SettingsFile, settings)) { - this->LogError("AutoGen: Error: Could not write old settings file " + - Quoted(this->SettingsFile)); + if (!this->FileWrite(cmQtAutoGen::GEN, this->SettingsFile, settings)) { + this->LogFileError(cmQtAutoGen::GEN, this->SettingsFile, + "Settings file writing failed"); // Remove old settings file to trigger a full rebuild on the next run cmSystemTools::RemoveFile(this->SettingsFile); success = false; @@ -631,157 +713,49 @@ bool cmQtAutoGenerators::SettingsFileWrite() return success; } -void cmQtAutoGenerators::Init(cmMakefile* makefile) -{ - // Mocs compilation file - this->MocCompFileRel = "mocs_compilation"; - this->MocCompFileRel += this->ConfigSuffix; - this->MocCompFileRel += ".cpp"; - this->MocCompFileAbs = cmSystemTools::CollapseCombinedPath( - this->AutogenBuildDir, this->MocCompFileRel); - - // Mocs include directory - this->AutogenIncludeDir = "include"; - this->AutogenIncludeDir += this->ConfigSuffix; - this->AutogenIncludeDir += "/"; - - // Moc predefs file - if (!this->MocPredefsCmd.empty()) { - this->MocPredefsFileRel = "moc_predefs.h"; - this->MocPredefsFileAbs = cmSystemTools::CollapseCombinedPath( - this->AutogenBuildDir, this->MocPredefsFileRel); - } - - // Init file path checksum generator - FPathChecksum.setupParentDirs(this->CurrentSourceDir, this->CurrentBinaryDir, - this->ProjectSourceDir, - this->ProjectBinaryDir); - - // Acquire header extensions - this->HeaderExtensions = makefile->GetCMakeInstance()->GetHeaderExtensions(); - - // Sort include directories on demand - if (this->IncludeProjectDirsBefore) { - // Move strings to temporary list - std::list includes; - includes.insert(includes.end(), this->MocIncludePaths.begin(), - this->MocIncludePaths.end()); - this->MocIncludePaths.clear(); - this->MocIncludePaths.reserve(includes.size()); - // Append project directories only - { - const char* movePaths[2] = { this->ProjectBinaryDir.c_str(), - this->ProjectSourceDir.c_str() }; - for (const char* const* mpit = cmArrayBegin(movePaths); - mpit != cmArrayEnd(movePaths); ++mpit) { - std::list::iterator it = includes.begin(); - while (it != includes.end()) { - const std::string& path = *it; - if (cmsys::SystemTools::StringStartsWith(path, *mpit)) { - this->MocIncludePaths.push_back(path); - it = includes.erase(it); - } else { - ++it; - } - } - } - } - // Append remaining directories - this->MocIncludePaths.insert(this->MocIncludePaths.end(), includes.begin(), - includes.end()); - } - // Compose moc includes list - { - std::set frameworkPaths; - for (std::vector::const_iterator it = - this->MocIncludePaths.begin(); - it != this->MocIncludePaths.end(); ++it) { - const std::string& path = *it; - this->MocIncludes.push_back("-I" + path); - // Extract framework path - if (cmHasLiteralSuffix(path, ".framework/Headers")) { - // Go up twice to get to the framework root - std::vector pathComponents; - cmsys::SystemTools::SplitPath(path, pathComponents); - std::string frameworkPath = cmsys::SystemTools::JoinPath( - pathComponents.begin(), pathComponents.end() - 2); - frameworkPaths.insert(frameworkPath); - } - } - // Append framework includes - for (std::set::const_iterator it = frameworkPaths.begin(); - it != frameworkPaths.end(); ++it) { - this->MocIncludes.push_back("-F"); - this->MocIncludes.push_back(*it); - } - } -} - -bool cmQtAutoGenerators::RunAutogen() +bool cmQtAutoGenerators::Process() { // the program goes through all .cpp files to see which moc files are // included. It is not really interesting how the moc file is named, but // what file the moc is created from. Once a moc is included the same moc - // may not be included in the mocs_compilation_$.cpp file anymore. + // may not be included in the mocs_compilation.cpp file anymore. // OTOH if there's a header containing Q_OBJECT where no corresponding // moc file is included anywhere a moc_.cpp file is created and - // included in the mocs_compilation_$.cpp file. + // included in the mocs_compilation.cpp file. // Create AUTOGEN include directory { - const std::string incDirAbs = cmSystemTools::CollapseCombinedPath( + std::string const incDirAbs = cmSystemTools::CollapseCombinedPath( this->AutogenBuildDir, this->AutogenIncludeDir); - if (!cmsys::SystemTools::MakeDirectory(incDirAbs)) { - this->LogError("AutoGen: Error: Could not create include directory " + - Quoted(incDirAbs)); + if (!cmSystemTools::MakeDirectory(incDirAbs)) { + this->LogFileError(cmQtAutoGen::GEN, incDirAbs, + "Could not create directory"); return false; } } - // key = moc source filepath, value = moc output filepath - std::map mocsIncluded; - std::map mocsNotIncluded; - std::map > mocDepends; - std::map > uisIncluded; - // collects all headers which may need to be mocced - std::set mocHeaderFiles; - std::set uicHeaderFiles; - - // Parse sources - for (std::vector::const_iterator it = this->Sources.begin(); - it != this->Sources.end(); ++it) { - const std::string& absFilename = cmsys::SystemTools::GetRealPath(*it); - // Parse source file for MOC/UIC - if (!this->ParseSourceFile(absFilename, mocsIncluded, mocDepends, - uisIncluded, this->MocRelaxedMode)) { + // Parse source files + for (const auto& item : this->SourceJobs) { + if (!this->ParseSourceFile(item.first, item.second)) { return false; } - // Find additional headers - this->SearchHeadersForSourceFile(absFilename, mocHeaderFiles, - uicHeaderFiles); } - - // Parse headers - for (std::vector::const_iterator it = this->Headers.begin(); - it != this->Headers.end(); ++it) { - const std::string& headerName = cmsys::SystemTools::GetRealPath(*it); - if (!this->MocSkip(headerName)) { - mocHeaderFiles.insert(headerName); - } - if (!this->UicSkip(headerName)) { - uicHeaderFiles.insert(headerName); + // Parse header files + for (const auto& item : this->HeaderJobs) { + if (!this->ParseHeaderFile(item.first, item.second)) { + return false; } } - if (!this->ParseHeaders(mocHeaderFiles, uicHeaderFiles, mocsIncluded, - mocsNotIncluded, mocDepends, uisIncluded)) { + // Read missing dependency information + if (!this->ParsePostprocess()) { return false; - }; + } // Generate files - if (!this->MocGenerateAll(mocsIncluded, mocsNotIncluded, mocDepends)) { + if (!this->MocGenerateAll()) { return false; } - if (!this->UicGenerateAll(uisIncluded)) { + if (!this->UicGenerateAll()) { return false; } if (!this->RccGenerateAll()) { @@ -792,72 +766,96 @@ bool cmQtAutoGenerators::RunAutogen() } /** - * @brief Tests if the C++ content requires moc processing - * @return True if moc is required + * @return True on success */ -bool cmQtAutoGenerators::MocRequired(const std::string& contentText, - std::string* macroName) +bool cmQtAutoGenerators::ParseSourceFile(std::string const& absFilename, + const SourceJob& job) { - for (unsigned int ii = 0; ii != cmArraySize(this->MocMacroFilters); ++ii) { - MocMacroFilter& filter = this->MocMacroFilters[ii]; - // Run a simple find string operation before the expensive - // regular expression check - if (contentText.find(filter.first) != std::string::npos) { - if (filter.second.find(contentText)) { - // Return macro name on demand - if (macroName != CM_NULLPTR) { - *macroName = filter.first; - } - return true; + std::string contentText; + std::string error; + bool success = ReadFile(contentText, absFilename, &error); + if (success) { + if (!contentText.empty()) { + if (job.Moc) { + success = this->MocParseSourceContent(absFilename, contentText); } + if (success && job.Uic) { + success = this->UicParseContent(absFilename, contentText); + } + } else { + this->LogFileWarning(cmQtAutoGen::GEN, absFilename, + "The source file is empty"); } + } else { + this->LogFileError(cmQtAutoGen::GEN, absFilename, + "Could not read the source file: " + error); } - return false; + return success; } -void cmQtAutoGenerators::MocFindDepends( - const std::string& absFilename, const std::string& contentText, - std::map >& mocDepends) +/** + * @return True on success + */ +bool cmQtAutoGenerators::ParseHeaderFile(std::string const& absFilename, + const SourceJob& job) { - for (std::vector::iterator fit = - this->MocDependFilters.begin(); - fit != this->MocDependFilters.end(); ++fit) { - MocDependFilter& filter = *fit; - // Run a simple find string operation before the expensive - // regular expression check - if (contentText.find(filter.key) != std::string::npos) { - // Run regular expression check loop - const std::string sourcePath = SubDirPrefix(absFilename); - const char* contentChars = contentText.c_str(); - while (filter.regExp.find(contentChars)) { - // Evaluate match - const std::string match = filter.regExp.match(1); - if (!match.empty()) { - // Find the dependency file - std::string incFile; - if (this->MocFindIncludedFile(incFile, sourcePath, match)) { - mocDepends[absFilename].insert(incFile); - if (this->Verbose) { - this->LogInfo("AutoMoc: Found dependency:\n " + - Quoted(absFilename) + "\n " + Quoted(incFile)); - } - } else { - this->LogWarning("AutoMoc: Warning: " + Quoted(absFilename) + - "\n" + "Could not find dependency file " + - Quoted(match)); - } - } - contentChars += filter.regExp.end(); + std::string contentText; + std::string error; + bool success = ReadFile(contentText, absFilename, &error); + if (success) { + if (!contentText.empty()) { + if (job.Moc) { + this->MocParseHeaderContent(absFilename, contentText); + } + if (job.Uic) { + success = this->UicParseContent(absFilename, contentText); + } + } else { + this->LogFileWarning(cmQtAutoGen::GEN, absFilename, + "The header file is empty"); + } + } else { + this->LogFileError(cmQtAutoGen::GEN, absFilename, + "Could not read the header file: " + error); + } + return success; +} + +/** + * @return True on success + */ +bool cmQtAutoGenerators::ParsePostprocess() +{ + bool success = true; + // Read missin dependecies + for (auto& item : this->MocJobsIncluded) { + if (!item->DependsValid) { + std::string content; + std::string error; + if (ReadFile(content, item->SourceFile, &error)) { + this->MocFindDepends(item->SourceFile, content, item->Depends); + item->DependsValid = true; + } else { + std::string emsg = "Could not read file\n "; + emsg += item->SourceFile; + emsg += "\nrequired by moc include \""; + emsg += item->IncludeString; + emsg += "\".\n"; + emsg += error; + this->LogFileError(cmQtAutoGen::MOC, item->Includer, emsg); + success = false; + break; } } } + return success; } /** * @brief Tests if the file should be ignored for moc scanning * @return True if the file should be ignored */ -bool cmQtAutoGenerators::MocSkip(const std::string& absFilename) const +bool cmQtAutoGenerators::MocSkip(std::string const& absFilename) const { if (this->MocEnabled()) { // Test if the file name is on the skip list @@ -869,68 +867,189 @@ bool cmQtAutoGenerators::MocSkip(const std::string& absFilename) const } /** - * @brief Tests if the file name is in the skip list + * @brief Tests if the C++ content requires moc processing + * @return True if moc is required */ -bool cmQtAutoGenerators::UicSkip(const std::string& absFilename) const +bool cmQtAutoGenerators::MocRequired(std::string const& contentText, + std::string* macroName) { - if (this->UicEnabled()) { - // Test if the file name is on the skip list - if (!ListContains(this->UicSkipList, absFilename)) { - return false; + for (KeyRegExp& filter : this->MocMacroFilters) { + // Run a simple find string operation before the expensive + // regular expression check + if (contentText.find(filter.Key) != std::string::npos) { + if (filter.RegExp.find(contentText)) { + // Return macro name on demand + if (macroName != nullptr) { + *macroName = filter.Key; + } + return true; + } } } - return true; + return false; } -/** - * @return True on success - */ -bool cmQtAutoGenerators::ParseSourceFile( - const std::string& absFilename, - std::map& mocsIncluded, - std::map >& mocDepends, - std::map >& uisIncluded, bool relaxed) +std::string cmQtAutoGenerators::MocStringMacros() const { - std::string contentText; - bool success = ReadAll(contentText, absFilename); - if (success) { - if (!contentText.empty()) { - // Parse source contents for MOC - if (success && !this->MocSkip(absFilename)) { - success = this->MocParseSourceContent( - absFilename, contentText, mocsIncluded, mocDepends, relaxed); + std::string res; + const auto itB = this->MocMacroFilters.cbegin(); + const auto itE = this->MocMacroFilters.cend(); + const auto itL = itE - 1; + auto itC = itB; + for (; itC != itE; ++itC) { + // Separator + if (itC != itB) { + if (itC != itL) { + res += ", "; + } else { + res += " or "; + } + } + // Key + res += itC->Key; + } + return res; +} + +std::string cmQtAutoGenerators::MocStringHeaders( + std::string const& fileBase) const +{ + std::string res = fileBase; + res += ".{"; + res += cmJoin(this->HeaderExtensions, ","); + res += "}"; + return res; +} + +std::string cmQtAutoGenerators::MocFindIncludedHeader( + std::string const& sourcePath, std::string const& includeBase) const +{ + std::string header; + // Search in vicinity of the source + if (!this->FindHeader(header, sourcePath + includeBase)) { + // Search in include directories + for (std::string const& path : this->MocIncludePaths) { + std::string fullPath = path; + fullPath.push_back('/'); + fullPath += includeBase; + if (this->FindHeader(header, fullPath)) { + break; + } + } + } + // Sanitize + if (!header.empty()) { + header = cmSystemTools::GetRealPath(header); + } + return header; +} + +bool cmQtAutoGenerators::MocFindIncludedFile( + std::string& absFile, std::string const& sourcePath, + std::string const& includeString) const +{ + bool success = false; + // Search in vicinity of the source + { + std::string testPath = sourcePath; + testPath += includeString; + if (cmSystemTools::FileExists(testPath.c_str())) { + absFile = cmSystemTools::GetRealPath(testPath); + success = true; + } + } + // Search in include directories + if (!success) { + for (std::string const& path : this->MocIncludePaths) { + std::string fullPath = path; + fullPath.push_back('/'); + fullPath += includeString; + if (cmSystemTools::FileExists(fullPath.c_str())) { + absFile = cmSystemTools::GetRealPath(fullPath); + success = true; + break; } - // Parse source contents for UIC - if (success && !this->UicSkip(absFilename)) { - this->UicParseContent(absFilename, contentText, uisIncluded); + } + } + return success; +} + +bool cmQtAutoGenerators::MocDependFilterPush(std::string const& key, + std::string const& regExp) +{ + std::string error; + if (!key.empty()) { + if (!regExp.empty()) { + KeyRegExp filter; + filter.Key = key; + if (filter.RegExp.compile(regExp)) { + this->MocDependFilters.push_back(std::move(filter)); + } else { + error = "Regular expression compiling failed"; } } else { - std::ostringstream ost; - ost << "AutoGen: Warning: The file is empty:\n" - << Quoted(absFilename) << "\n"; - this->LogWarning(ost.str()); + error = "Regular expression is empty"; } } else { - std::ostringstream ost; - ost << "AutoGen: Error: Could not read file:\n" << Quoted(absFilename); - this->LogError(ost.str()); + error = "Key is empty"; } - return success; + if (!error.empty()) { + std::string emsg = "AUTOMOC_DEPEND_FILTERS: "; + emsg += error; + emsg += "\n"; + emsg += " Key: "; + emsg += cmQtAutoGen::Quoted(key); + emsg += "\n"; + emsg += " RegExp: "; + emsg += cmQtAutoGen::Quoted(regExp); + emsg += "\n"; + this->LogError(cmQtAutoGen::MOC, emsg); + return false; + } + return true; } -void cmQtAutoGenerators::UicParseContent( - const std::string& absFilename, const std::string& contentText, - std::map >& uisIncluded) +void cmQtAutoGenerators::MocFindDepends(std::string const& absFilename, + std::string const& contentText, + std::set& depends) { - if (this->Verbose) { - this->LogInfo("AutoUic: Checking " + absFilename); + if (this->MocDependFilters.empty() && contentText.empty()) { + return; + } + + std::vector matches; + for (KeyRegExp& filter : this->MocDependFilters) { + // Run a simple find string check + if (contentText.find(filter.Key) != std::string::npos) { + // Run the expensive regular expression check loop + const char* contentChars = contentText.c_str(); + while (filter.RegExp.find(contentChars)) { + std::string match = filter.RegExp.match(1); + if (!match.empty()) { + matches.emplace_back(std::move(match)); + } + contentChars += filter.RegExp.end(); + } + } } - const char* contentChars = contentText.c_str(); - if (strstr(contentChars, "ui_") != CM_NULLPTR) { - while (this->UicRegExpInclude.find(contentChars)) { - uisIncluded[absFilename].push_back(this->UicRegExpInclude.match(1)); - contentChars += this->UicRegExpInclude.end(); + if (!matches.empty()) { + std::string const sourcePath = SubDirPrefix(absFilename); + for (std::string const& match : matches) { + // Find the dependency file + std::string incFile; + if (this->MocFindIncludedFile(incFile, sourcePath, match)) { + depends.insert(incFile); + if (this->Verbose) { + this->LogInfo(cmQtAutoGen::MOC, "Found dependency:\n " + + cmQtAutoGen::Quoted(absFilename) + "\n " + + cmQtAutoGen::Quoted(incFile)); + } + } else { + this->LogFileWarning(cmQtAutoGen::MOC, absFilename, + "Could not find dependency file " + + cmQtAutoGen::Quoted(match)); + } } } } @@ -938,322 +1057,336 @@ void cmQtAutoGenerators::UicParseContent( /** * @return True on success */ -bool cmQtAutoGenerators::MocParseSourceContent( - const std::string& absFilename, const std::string& contentText, - std::map& mocsIncluded, - std::map >& mocDepends, bool relaxed) +bool cmQtAutoGenerators::MocParseSourceContent(std::string const& absFilename, + std::string const& contentText) { if (this->Verbose) { - this->LogInfo("AutoMoc: Checking " + absFilename); - } + this->LogInfo(cmQtAutoGen::MOC, "Checking: " + absFilename); + } + + auto AddJob = [this, &absFilename](std::string const& sourceFile, + std::string const& includeString, + std::string const* content) { + auto job = cm::make_unique(); + job->SourceFile = sourceFile; + job->BuildFileRel = this->AutogenIncludeDir; + job->BuildFileRel += includeString; + job->Includer = absFilename; + job->IncludeString = includeString; + job->DependsValid = (content != nullptr); + if (job->DependsValid) { + this->MocFindDepends(sourceFile, *content, job->Depends); + } + this->MocJobsIncluded.push_back(std::move(job)); + }; - const std::string scannedFileAbsPath = SubDirPrefix(absFilename); - const std::string scannedFileBasename = - cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename); + struct MocInc + { + std::string Inc; // full include string + std::string Dir; // include string directory + std::string Base; // include string file base + }; - std::string macroName; - const bool requiresMoc = this->MocRequired(contentText, ¯oName); - bool ownDotMocIncluded = false; - std::string ownMocUnderscoreInclude; - std::string ownMocUnderscoreHeader; - - // first a simple string check for "moc" is *much* faster than the regexp, - // and if the string search already fails, we don't have to try the - // expensive regexp - const char* contentChars = contentText.c_str(); - if (strstr(contentChars, "moc") != CM_NULLPTR) { - // Iterate over all included moc files - while (this->MocRegExpInclude.find(contentChars)) { - const std::string incString = this->MocRegExpInclude.match(1); - // Basename of the moc include - const std::string incSubDir(SubDirPrefix(incString)); - const std::string incBasename = - cmsys::SystemTools::GetFilenameWithoutLastExtension(incString); - - // If the moc include is of the moc_foo.cpp style we expect - // the Q_OBJECT class declaration in a header file. - // If the moc include is of the foo.moc style we need to look for - // a Q_OBJECT macro in the current source file, if it contains the - // macro we generate the moc file from the source file. - if (cmHasLiteralPrefix(incBasename, "moc_")) { - // Include: moc_FOO.cxx - // Remove the moc_ part - const std::string incRealBasename = incBasename.substr(4); - const std::string headerToMoc = - this->MocFindHeader(scannedFileAbsPath, incSubDir + incRealBasename); - if (!headerToMoc.empty()) { - if (!this->MocSkip(headerToMoc)) { - // Register moc job - mocsIncluded[headerToMoc] = incString; - this->MocFindDepends(headerToMoc, contentText, mocDepends); - // Store meta information for relaxed mode - if (relaxed && (incRealBasename == scannedFileBasename)) { - ownMocUnderscoreInclude = incString; - ownMocUnderscoreHeader = headerToMoc; - } - } + // Extract moc includes from file + std::vector mocIncsUsc; + std::vector mocIncsDot; + { + const char* contentChars = contentText.c_str(); + if (strstr(contentChars, "moc") != nullptr) { + while (this->MocRegExpInclude.find(contentChars)) { + std::string incString = this->MocRegExpInclude.match(1); + std::string incDir(SubDirPrefix(incString)); + std::string incBase = + cmSystemTools::GetFilenameWithoutLastExtension(incString); + if (cmHasLiteralPrefix(incBase, "moc_")) { + // moc_.cxx + // Remove the moc_ part from the base name + mocIncsUsc.push_back(MocInc{ std::move(incString), std::move(incDir), + incBase.substr(4) }); } else { - std::ostringstream ost; - ost << "AutoMoc: Error: " << Quoted(absFilename) << "\n" - << "The file includes the moc file " << Quoted(incString) - << ", but could not find header " - << Quoted(incRealBasename + "{" + - JoinExts(this->HeaderExtensions) + "}"); - ; - this->LogError(ost.str()); - return false; + // .moc + mocIncsDot.push_back(MocInc{ std::move(incString), std::move(incDir), + std::move(incBase) }); } + // Forward content pointer + contentChars += this->MocRegExpInclude.end(); + } + } + } + + std::string selfMacroName; + const bool selfRequiresMoc = this->MocRequired(contentText, &selfMacroName); + + // Check if there is anything to do + if (!selfRequiresMoc && mocIncsUsc.empty() && mocIncsDot.empty()) { + return true; + } + + // Scan file variables + std::string const scanFileDir = SubDirPrefix(absFilename); + std::string const scanFileBase = + cmSystemTools::GetFilenameWithoutLastExtension(absFilename); + // Relaxed mode variables + bool ownDotMocIncluded = false; + std::string ownMocUscInclude; + std::string ownMocUscHeader; + + // Process moc_.cxx includes + for (const MocInc& mocInc : mocIncsUsc) { + std::string const header = + this->MocFindIncludedHeader(scanFileDir, mocInc.Dir + mocInc.Base); + if (!header.empty()) { + // Check if header is skipped + if (this->MocSkip(header)) { + continue; + } + // Register moc job + AddJob(header, mocInc.Inc, nullptr); + // Store meta information for relaxed mode + if (this->MocRelaxedMode && (mocInc.Base == scanFileBase)) { + ownMocUscInclude = mocInc.Inc; + ownMocUscHeader = header; + } + } else { + std::string emsg = "The file includes the moc file "; + emsg += cmQtAutoGen::Quoted(mocInc.Inc); + emsg += ", but could not find the header "; + emsg += cmQtAutoGen::Quoted(this->MocStringHeaders(mocInc.Base)); + this->LogFileError(cmQtAutoGen::MOC, absFilename, emsg); + return false; + } + } + + // Process .moc includes + for (const MocInc& mocInc : mocIncsDot) { + const bool ownMoc = (mocInc.Base == scanFileBase); + if (this->MocRelaxedMode) { + // Relaxed mode + if (selfRequiresMoc && ownMoc) { + // Add self + AddJob(absFilename, mocInc.Inc, &contentText); + ownDotMocIncluded = true; } else { - // Include: FOO.moc - std::string fileToMoc; - if (relaxed) { - // Mode: Relaxed - if (requiresMoc && (incBasename == scannedFileBasename)) { - // Include self - fileToMoc = absFilename; - ownDotMocIncluded = true; - } else { - // In relaxed mode try to find a header instead but issue a warning - const std::string headerToMoc = - this->MocFindHeader(scannedFileAbsPath, incSubDir + incBasename); - if (!headerToMoc.empty()) { - if (!this->MocSkip(headerToMoc)) { - // This is for KDE4 compatibility: - fileToMoc = headerToMoc; - if (!requiresMoc && (incBasename == scannedFileBasename)) { - std::ostringstream ost; - ost - << "AutoMoc: Warning: " << Quoted(absFilename) << "\n" - << "The file includes the moc file " << Quoted(incString) - << ", but does not contain a Q_OBJECT or Q_GADGET macro.\n" - << "Running moc on " << Quoted(headerToMoc) << "!\n" - << "Include " << Quoted("moc_" + incBasename + ".cpp") - << " for a compatibility with strict mode (see " - "CMAKE_AUTOMOC_RELAXED_MODE).\n"; - this->LogWarning(ost.str()); - } else { - std::ostringstream ost; - ost << "AutoMoc: Warning: " << Quoted(absFilename) << "\n" - << "The file includes the moc file " << Quoted(incString) - << " instead of " - << Quoted("moc_" + incBasename + ".cpp") << ".\n" - << "Running moc on " << Quoted(headerToMoc) << "!\n" - << "Include " << Quoted("moc_" + incBasename + ".cpp") - << " for compatibility with strict mode (see " - "CMAKE_AUTOMOC_RELAXED_MODE).\n"; - this->LogWarning(ost.str()); - } - } + // In relaxed mode try to find a header instead but issue a warning. + // This is for KDE4 compatibility + std::string const header = + this->MocFindIncludedHeader(scanFileDir, mocInc.Dir + mocInc.Base); + if (!header.empty()) { + // Check if header is skipped + if (this->MocSkip(header)) { + continue; + } + // Register moc job + AddJob(header, mocInc.Inc, nullptr); + if (!selfRequiresMoc) { + if (ownMoc) { + std::string emsg = "The file includes the moc file "; + emsg += cmQtAutoGen::Quoted(mocInc.Inc); + emsg += ", but does not contain a "; + emsg += this->MocStringMacros(); + emsg += " macro.\nRunning moc on\n "; + emsg += cmQtAutoGen::Quoted(header); + emsg += "!\nBetter include "; + emsg += cmQtAutoGen::Quoted("moc_" + mocInc.Base + ".cpp"); + emsg += " for a compatibility with strict mode.\n" + "(CMAKE_AUTOMOC_RELAXED_MODE warning)\n"; + this->LogFileWarning(cmQtAutoGen::MOC, absFilename, emsg); } else { - std::ostringstream ost; - ost << "AutoMoc: Error: " << Quoted(absFilename) << "\n" - << "The file includes the moc file " << Quoted(incString) - << ", which seems to be the moc file from a different " - "source file. CMake also could not find a matching " - "header."; - this->LogError(ost.str()); - return false; + std::string emsg = "The file includes the moc file "; + emsg += cmQtAutoGen::Quoted(mocInc.Inc); + emsg += " instead of "; + emsg += cmQtAutoGen::Quoted("moc_" + mocInc.Base + ".cpp"); + emsg += ".\nRunning moc on\n "; + emsg += cmQtAutoGen::Quoted(header); + emsg += "!\nBetter include "; + emsg += cmQtAutoGen::Quoted("moc_" + mocInc.Base + ".cpp"); + emsg += " for compatibility with strict mode.\n" + "(CMAKE_AUTOMOC_RELAXED_MODE warning)\n"; + this->LogFileWarning(cmQtAutoGen::MOC, absFilename, emsg); } } } else { - // Mode: Strict - if (incBasename == scannedFileBasename) { - // Include self - fileToMoc = absFilename; - ownDotMocIncluded = true; - // Accept but issue a warning if moc isn't required - if (!requiresMoc) { - std::ostringstream ost; - ost << "AutoMoc: Warning: " << Quoted(absFilename) << "\n" - << "The file includes the moc file " << Quoted(incString) - << ", but does not contain a Q_OBJECT or Q_GADGET " - "macro."; - this->LogWarning(ost.str()); - } - } else { - // Don't allow FOO.moc include other than self in strict mode - std::ostringstream ost; - ost << "AutoMoc: Error: " << Quoted(absFilename) << "\n" - << "The file includes the moc file " << Quoted(incString) - << ", which seems to be the moc file from a different " - "source file. This is not supported. Include " - << Quoted(scannedFileBasename + ".moc") - << " to run moc on this source file."; - this->LogError(ost.str()); - return false; - } + std::string emsg = "The file includes the moc file "; + emsg += cmQtAutoGen::Quoted(mocInc.Inc); + emsg += ", which seems to be the moc file from a different " + "source file. CMake also could not find a matching " + "header."; + this->LogFileError(cmQtAutoGen::MOC, absFilename, emsg); + return false; } - if (!fileToMoc.empty()) { - mocsIncluded[fileToMoc] = incString; - this->MocFindDepends(fileToMoc, contentText, mocDepends); + } + } else { + // Strict mode + if (ownMoc) { + // Include self + AddJob(absFilename, mocInc.Inc, &contentText); + ownDotMocIncluded = true; + // Accept but issue a warning if moc isn't required + if (!selfRequiresMoc) { + std::string emsg = "The file includes the moc file "; + emsg += cmQtAutoGen::Quoted(mocInc.Inc); + emsg += ", but does not contain a "; + emsg += this->MocStringMacros(); + emsg += " macro."; + this->LogFileWarning(cmQtAutoGen::MOC, absFilename, emsg); } + } else { + // Don't allow .moc include other than self in strict mode + std::string emsg = "The file includes the moc file "; + emsg += cmQtAutoGen::Quoted(mocInc.Inc); + emsg += ", which seems to be the moc file from a different " + "source file.\nThis is not supported. Include "; + emsg += cmQtAutoGen::Quoted(scanFileBase + ".moc"); + emsg += " to run moc on this source file."; + this->LogFileError(cmQtAutoGen::MOC, absFilename, emsg); + return false; } - // Forward content pointer - contentChars += this->MocRegExpInclude.end(); } } - if (requiresMoc && !ownDotMocIncluded) { + if (selfRequiresMoc && !ownDotMocIncluded) { // In this case, check whether the scanned file itself contains a Q_OBJECT. // If this is the case, the moc_foo.cpp should probably be generated from // foo.cpp instead of foo.h, because otherwise it won't build. // But warn, since this is not how it is supposed to be used. - if (relaxed && !ownMocUnderscoreInclude.empty()) { + if (this->MocRelaxedMode && !ownMocUscInclude.empty()) { // This is for KDE4 compatibility: - std::ostringstream ost; - ost << "AutoMoc: Warning: " << Quoted(absFilename) << "\n" - << "The file contains a " << macroName - << " macro, but does not include " - << Quoted(scannedFileBasename + ".moc") << ", but instead includes " - << Quoted(ownMocUnderscoreInclude) << ".\n" - << "Running moc on " << Quoted(absFilename) << "!\n" - << "Better include " << Quoted(scannedFileBasename + ".moc") - << " for compatibility with strict mode (see " - "CMAKE_AUTOMOC_RELAXED_MODE)."; - this->LogWarning(ost.str()); - - // Use scanned source file instead of scanned header file as moc source - mocsIncluded[absFilename] = ownMocUnderscoreInclude; - this->MocFindDepends(absFilename, contentText, mocDepends); - // Remove - mocsIncluded.erase(ownMocUnderscoreHeader); + std::string emsg = "The file contains a "; + emsg += selfMacroName; + emsg += " macro, but does not include "; + emsg += cmQtAutoGen::Quoted(scanFileBase + ".moc"); + emsg += ". Instead it includes "; + emsg += cmQtAutoGen::Quoted(ownMocUscInclude); + emsg += ".\nRunning moc on\n "; + emsg += cmQtAutoGen::Quoted(absFilename); + emsg += "!\nBetter include "; + emsg += cmQtAutoGen::Quoted(scanFileBase + ".moc"); + emsg += " for compatibility with strict mode.\n" + "(CMAKE_AUTOMOC_RELAXED_MODE warning)"; + this->LogFileWarning(cmQtAutoGen::MOC, absFilename, emsg); + + // Remove own header job + { + auto itC = this->MocJobsIncluded.begin(); + auto itE = this->MocJobsIncluded.end(); + for (; itC != itE; ++itC) { + if ((*itC)->SourceFile == ownMocUscHeader) { + if ((*itC)->IncludeString == ownMocUscInclude) { + this->MocJobsIncluded.erase(itC); + break; + } + } + } + } + // Add own source job + AddJob(absFilename, ownMocUscInclude, &contentText); } else { // Otherwise always error out since it will not compile: - std::ostringstream ost; - ost << "AutoMoc: Error: " << Quoted(absFilename) << "\n" - << "The file contains a " << macroName - << " macro, but does not include " - << Quoted(scannedFileBasename + ".moc") << "!\n" - << "Consider adding the include or enabling SKIP_AUTOMOC for this " - "file."; - this->LogError(ost.str()); + std::string emsg = "The file contains a "; + emsg += selfMacroName; + emsg += " macro, but does not include "; + emsg += cmQtAutoGen::Quoted(scanFileBase + ".moc"); + emsg += "!\nConsider to\n - add #include \""; + emsg += scanFileBase; + emsg += ".moc\"\n - enable SKIP_AUTOMOC for this file"; + this->LogFileError(cmQtAutoGen::MOC, absFilename, emsg); return false; } } - return true; } -void cmQtAutoGenerators::MocParseHeaderContent( - const std::string& absFilename, const std::string& contentText, - std::map& mocsNotIncluded, - std::map >& mocDepends) +void cmQtAutoGenerators::MocParseHeaderContent(std::string const& absFilename, + std::string const& contentText) { - // Log if (this->Verbose) { - this->LogInfo("AutoMoc: Checking " + absFilename); - } - if (this->MocRequired(contentText)) { - // Register moc job - mocsNotIncluded[absFilename] = - this->ChecksumedPath(absFilename, "moc_", this->ConfigSuffix + ".cpp"); - this->MocFindDepends(absFilename, contentText, mocDepends); - } -} - -void cmQtAutoGenerators::SearchHeadersForSourceFile( - const std::string& absFilename, std::set& mocHeaderFiles, - std::set& uicHeaderFiles) const -{ - std::string basepaths[2]; - { - std::string bpath = SubDirPrefix(absFilename); - bpath += cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename); - // search for default header files and private header files - basepaths[0] = bpath; - basepaths[1] = bpath + "_p"; - } - - for (const std::string* bpit = cmArrayBegin(basepaths); - bpit != cmArrayEnd(basepaths); ++bpit) { - std::string headerName; - if (this->FindHeader(headerName, *bpit)) { - // Moc headers - if (!this->MocSkip(absFilename) && !this->MocSkip(headerName)) { - mocHeaderFiles.insert(headerName); - } - // Uic headers - if (!this->UicSkip(absFilename) && !this->UicSkip(headerName)) { - uicHeaderFiles.insert(headerName); - } - } - } -} - -bool cmQtAutoGenerators::ParseHeaders( - const std::set& mocHeaderFiles, - const std::set& uicHeaderFiles, - const std::map& mocsIncluded, - std::map& mocsNotIncluded, - std::map >& mocDepends, - std::map >& uisIncluded) -{ - bool success = true; - // Merged header files list to read files only once - std::set headerFiles; - headerFiles.insert(mocHeaderFiles.begin(), mocHeaderFiles.end()); - headerFiles.insert(uicHeaderFiles.begin(), uicHeaderFiles.end()); - - for (std::set::const_iterator hIt = headerFiles.begin(); - hIt != headerFiles.end(); ++hIt) { - const std::string& headerName = *hIt; - std::string contentText; - if (ReadAll(contentText, headerName)) { - // Parse header content for MOC - if ((mocHeaderFiles.find(headerName) != mocHeaderFiles.end()) && - (mocsIncluded.find(headerName) == mocsIncluded.end())) { - this->MocParseHeaderContent(headerName, contentText, mocsNotIncluded, - mocDepends); - } - // Parse header content for UIC - if (uicHeaderFiles.find(headerName) != uicHeaderFiles.end()) { - this->UicParseContent(headerName, contentText, uisIncluded); + this->LogInfo(cmQtAutoGen::MOC, "Checking: " + absFilename); + } + + auto const fit = + std::find_if(this->MocJobsIncluded.cbegin(), this->MocJobsIncluded.cend(), + [&absFilename](std::unique_ptr const& job) { + return job->SourceFile == absFilename; + }); + if (fit == this->MocJobsIncluded.cend()) { + if (this->MocRequired(contentText)) { + auto job = cm::make_unique(); + job->SourceFile = absFilename; + { + std::string& bld = job->BuildFileRel; + bld = this->FilePathChecksum.getPart(absFilename); + bld += '/'; + bld += "moc_"; + bld += cmSystemTools::GetFilenameWithoutLastExtension(absFilename); + if (this->MultiConfig != cmQtAutoGen::SINGLE) { + bld += this->ConfigSuffix; + } + bld += ".cpp"; } - } else { - std::ostringstream ost; - ost << "AutoGen: Error: Could not read header file:\n" - << Quoted(headerName); - this->LogError(ost.str()); - success = false; - break; + this->MocFindDepends(absFilename, contentText, job->Depends); + this->MocJobsAuto.push_back(std::move(job)); } } - return success; } -bool cmQtAutoGenerators::MocGenerateAll( - const std::map& mocsIncluded, - const std::map& mocsNotIncluded, - const std::map >& mocDepends) +bool cmQtAutoGenerators::MocGenerateAll() { if (!this->MocEnabled()) { return true; } - // Look for name collisions + // Look for name collisions in included moc files { - std::multimap collisions; - // Test merged map of included and notIncluded - std::map mergedMocs(mocsIncluded); - mergedMocs.insert(mocsNotIncluded.begin(), mocsNotIncluded.end()); - if (this->NameCollisionTest(mergedMocs, collisions)) { - std::ostringstream ost; - ost << "AutoMoc: Error: " - "The same moc file will be generated " - "from different sources.\n" - "To avoid this error either\n" - "- rename the source files or\n" - "- do not include the (moc_NAME.cpp|NAME.moc) file"; - this->LogErrorNameCollision(ost.str(), collisions); + bool collision = false; + std::map> collisions; + for (auto const& job : this->MocJobsIncluded) { + auto& list = collisions[job->IncludeString]; + if (!list.empty()) { + collision = true; + } + list.push_back(job.get()); + } + if (collision) { + std::string emsg = + "Included moc files with the same name will be " + "generated from different sources.\n" + "Consider to\n" + " - not include the \"moc_.cpp\" file\n" + " - add a directory prefix to a \".moc\" include " + "(e.g \"sub/.moc\")\n" + " - rename the source file(s)\n" + "Include conflicts\n" + "-----------------\n"; + const auto& colls = collisions; + for (auto const& coll : colls) { + if (coll.second.size() > 1) { + emsg += cmQtAutoGen::Quoted(coll.first); + emsg += " included in\n"; + for (const MocJobIncluded* job : coll.second) { + emsg += " - "; + emsg += cmQtAutoGen::Quoted(job->Includer); + emsg += "\n"; + } + emsg += "would be generated from\n"; + for (const MocJobIncluded* job : coll.second) { + emsg += " - "; + emsg += cmQtAutoGen::Quoted(job->SourceFile); + emsg += "\n"; + } + } + } + this->LogError(cmQtAutoGen::MOC, emsg); return false; } } - // Generate moc_predefs + // (Re)generate moc_predefs.h on demand if (!this->MocPredefsCmd.empty()) { if (this->MocSettingsChanged || - FileAbsentOrOlder(this->MocPredefsFileAbs, this->SettingsFile)) { - this->LogBold("Generating MOC predefs " + this->MocPredefsFileRel); + !cmSystemTools::FileExists(this->MocPredefsFileAbs)) { + if (this->Verbose) { + this->LogBold("Generating MOC predefs " + this->MocPredefsFileRel); + } std::string output; { @@ -1263,149 +1396,200 @@ bool cmQtAutoGenerators::MocGenerateAll( cmd.insert(cmd.end(), this->MocIncludes.begin(), this->MocIncludes.end()); // Add definitions - for (std::vector::const_iterator it = - this->MocDefinitions.begin(); - it != this->MocDefinitions.end(); ++it) { - cmd.push_back("-D" + (*it)); + for (std::string const& def : this->MocDefinitions) { + cmd.push_back("-D" + def); } // Execute command - if (!this->RunCommand(cmd, output, false)) { - { - std::ostringstream ost; - ost << "AutoMoc: Error: moc predefs generation command failed\n"; - ost << "AutoMoc: Command:\n" << QuotedCommand(cmd) << "\n"; - ost << "AutoMoc: Command output:\n" << output << "\n"; - this->LogError(ost.str()); - } + if (!this->RunCommand(cmd, output)) { + this->LogCommandError(cmQtAutoGen::MOC, + "moc_predefs generation failed", cmd, output); return false; } } + // (Re)write predefs file only on demand if (this->FileDiffers(this->MocPredefsFileAbs, output)) { - if (this->FileWrite("AutoMoc", this->MocPredefsFileAbs, output)) { + if (this->FileWrite(cmQtAutoGen::MOC, this->MocPredefsFileAbs, + output)) { this->MocPredefsChanged = true; } else { + this->LogFileError(cmQtAutoGen::MOC, this->MocPredefsFileAbs, + "moc_predefs file writing failed"); return false; } + } else { + // Touch to update the time stamp + if (this->Verbose) { + this->LogInfo(cmQtAutoGen::MOC, + "Touching moc_predefs " + this->MocPredefsFileRel); + } + cmSystemTools::Touch(this->MocPredefsFileAbs, false); } } + + // Add moc_predefs.h to moc file dependecies + for (auto const& item : this->MocJobsIncluded) { + item->Depends.insert(this->MocPredefsFileAbs); + } + for (auto const& item : this->MocJobsAuto) { + item->Depends.insert(this->MocPredefsFileAbs); + } } // Generate moc files that are included by source files. - for (std::map::const_iterator it = - mocsIncluded.begin(); - it != mocsIncluded.end(); ++it) { - if (!this->MocGenerateFile(it->first, it->second, mocDepends, true)) { - if (this->MocRunFailed) { - return false; - } + for (auto const& item : this->MocJobsIncluded) { + if (!this->MocGenerateFile(*item)) { + return false; } } - // Generate moc files that are _not_ included by source files. - bool mocCompFileGenerated = false; - for (std::map::const_iterator it = - mocsNotIncluded.begin(); - it != mocsNotIncluded.end(); ++it) { - if (this->MocGenerateFile(it->first, it->second, mocDepends, false)) { - mocCompFileGenerated = true; - } else { - if (this->MocRunFailed) { - return false; - } + bool autoNameGenerated = false; + for (auto const& item : this->MocJobsAuto) { + if (!this->MocGenerateFile(*item, &autoNameGenerated)) { + return false; } } // Compose mocs compilation file content - std::string automocSource; { - std::ostringstream ost; - ost << "/* This file is autogenerated, do not edit*/\n"; - if (mocsNotIncluded.empty()) { - // Dummy content - ost << "enum some_compilers { need_more_than_nothing };\n"; + std::string mocs = + "// This file is autogenerated. Changes will be overwritten.\n"; + if (this->MocJobsAuto.empty()) { + // Placeholder content + mocs += + "// No files found that require moc or the moc files are included\n"; + mocs += "enum some_compilers { need_more_than_nothing };\n"; } else { // Valid content - for (std::map::const_iterator it = - mocsNotIncluded.begin(); - it != mocsNotIncluded.end(); ++it) { - ost << "#include \"" << it->second << "\"\n"; + for (const auto& item : this->MocJobsAuto) { + mocs += "#include \""; + mocs += item->BuildFileRel; + mocs += "\"\n"; } } - automocSource = ost.str(); - } - if (this->FileDiffers(this->MocCompFileAbs, automocSource)) { - // Actually write mocs compilation file - this->LogBold("Generating MOC compilation " + this->MocCompFileRel); - if (!this->FileWrite("AutoMoc", this->MocCompFileAbs, automocSource)) { - return false; - } - } else if (mocCompFileGenerated) { - // Only touch mocs compilation file - if (this->Verbose) { - this->LogInfo("Touching MOC compilation " + this->MocCompFileRel); + if (this->FileDiffers(this->MocCompFileAbs, mocs)) { + // Actually write mocs compilation file + if (this->Verbose) { + this->LogBold("Generating MOC compilation " + this->MocCompFileRel); + } + if (!this->FileWrite(cmQtAutoGen::MOC, this->MocCompFileAbs, mocs)) { + this->LogFileError(cmQtAutoGen::MOC, this->MocCompFileAbs, + "mocs compilation file writing failed"); + return false; + } + } else if (autoNameGenerated) { + // Only touch mocs compilation file + if (this->Verbose) { + this->LogInfo(cmQtAutoGen::MOC, + "Touching mocs compilation " + this->MocCompFileRel); + } + cmSystemTools::Touch(this->MocCompFileAbs, false); } - cmSystemTools::Touch(this->MocCompFileAbs, false); } return true; } /** - * @return True if a moc file was created. False may indicate an error. + * @return True on success */ -bool cmQtAutoGenerators::MocGenerateFile( - const std::string& sourceFile, const std::string& mocFileName, - const std::map >& mocDepends, - bool included) +bool cmQtAutoGenerators::MocGenerateFile(const MocJobAuto& mocJob, + bool* generated) { - bool mocGenerated = false; - bool generateMoc = this->MocSettingsChanged || this->MocPredefsChanged; - - const std::string mocFileRel = - included ? (this->AutogenIncludeDir + mocFileName) : mocFileName; - const std::string mocFileAbs = - cmSystemTools::CollapseCombinedPath(this->AutogenBuildDir, mocFileRel); - - if (!generateMoc) { - // Test if the source file is newer that the build file - generateMoc = FileAbsentOrOlder(mocFileAbs, sourceFile); - if (!generateMoc) { - // Test if a dependency file changed - std::map >::const_iterator dit = - mocDepends.find(sourceFile); - if (dit != mocDepends.end()) { - for (std::set::const_iterator fit = dit->second.begin(); - fit != dit->second.end(); ++fit) { - if (FileAbsentOrOlder(mocFileAbs, *fit)) { - generateMoc = true; - break; - } + bool success = true; + + std::string const mocFileAbs = cmSystemTools::CollapseCombinedPath( + this->AutogenBuildDir, mocJob.BuildFileRel); + + bool generate = false; + std::string generateReason; + if (!generate && !cmSystemTools::FileExists(mocFileAbs.c_str())) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(mocFileAbs); + generateReason += " from its source file "; + generateReason += cmQtAutoGen::Quoted(mocJob.SourceFile); + generateReason += " because it doesn't exist"; + } + generate = true; + } + if (!generate && this->MocSettingsChanged) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(mocFileAbs); + generateReason += " from "; + generateReason += cmQtAutoGen::Quoted(mocJob.SourceFile); + generateReason += " because the MOC settings changed"; + } + generate = true; + } + if (!generate && this->MocPredefsChanged) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(mocFileAbs); + generateReason += " from "; + generateReason += cmQtAutoGen::Quoted(mocJob.SourceFile); + generateReason += " because moc_predefs.h changed"; + } + generate = true; + } + if (!generate) { + std::string error; + if (FileIsOlderThan(mocFileAbs, mocJob.SourceFile, &error)) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(mocFileAbs); + generateReason += " because it's older than its source file "; + generateReason += cmQtAutoGen::Quoted(mocJob.SourceFile); + } + generate = true; + } else { + if (!error.empty()) { + this->LogError(cmQtAutoGen::MOC, error); + success = false; + } + } + } + if (success && !generate) { + // Test if a dependency file is newer + std::string error; + for (std::string const& depFile : mocJob.Depends) { + if (FileIsOlderThan(mocFileAbs, depFile, &error)) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(mocFileAbs); + generateReason += " from "; + generateReason += cmQtAutoGen::Quoted(mocJob.SourceFile); + generateReason += " because it is older than "; + generateReason += cmQtAutoGen::Quoted(depFile); } + generate = true; + break; + } + if (!error.empty()) { + this->LogError(cmQtAutoGen::MOC, error); + success = false; + break; } } } - if (generateMoc) { + + if (generate) { // Log - this->LogBold("Generating MOC source " + mocFileRel); + if (this->Verbose) { + this->LogBold("Generating MOC source " + mocJob.BuildFileRel); + this->LogInfo(cmQtAutoGen::MOC, generateReason); + } // Make sure the parent directory exists - if (this->MakeParentDirectory("AutoMoc", mocFileAbs)) { + if (this->MakeParentDirectory(cmQtAutoGen::MOC, mocFileAbs)) { // Compose moc command std::vector cmd; cmd.push_back(this->MocExecutable); - // Add includes - cmd.insert(cmd.end(), this->MocIncludes.begin(), - this->MocIncludes.end()); - // Add definitions - for (std::vector::const_iterator it = - this->MocDefinitions.begin(); - it != this->MocDefinitions.end(); ++it) { - cmd.push_back("-D" + (*it)); - } // Add options - cmd.insert(cmd.end(), this->MocOptions.begin(), this->MocOptions.end()); + cmd.insert(cmd.end(), this->MocAllOptions.begin(), + this->MocAllOptions.end()); // Add predefs include if (!this->MocPredefsFileAbs.empty()) { cmd.push_back("--include"); @@ -1413,47 +1597,119 @@ bool cmQtAutoGenerators::MocGenerateFile( } cmd.push_back("-o"); cmd.push_back(mocFileAbs); - cmd.push_back(sourceFile); + cmd.push_back(mocJob.SourceFile); // Execute moc command std::string output; if (this->RunCommand(cmd, output)) { // Success - mocGenerated = true; + if (generated != nullptr) { + *generated = true; + } } else { - // Command failed + // Moc command failed { - std::ostringstream ost; - ost << "AutoMoc: Error: moc process failed for\n"; - ost << Quoted(mocFileRel) << "\n"; - ost << "AutoMoc: Command:\n" << QuotedCommand(cmd) << "\n"; - ost << "AutoMoc: Command output:\n" << output << "\n"; - this->LogError(ost.str()); + std::string emsg = "moc failed for\n "; + emsg += cmQtAutoGen::Quoted(mocJob.SourceFile); + this->LogCommandError(cmQtAutoGen::MOC, emsg, cmd, output); } cmSystemTools::RemoveFile(mocFileAbs); - this->MocRunFailed = true; + success = false; } } else { // Parent directory creation failed - this->MocRunFailed = true; + success = false; + } + } + return success; +} + +/** + * @brief Tests if the file name is in the skip list + */ +bool cmQtAutoGenerators::UicSkip(std::string const& absFilename) const +{ + if (this->UicEnabled()) { + // Test if the file name is on the skip list + if (!ListContains(this->UicSkipList, absFilename)) { + return false; + } + } + return true; +} + +bool cmQtAutoGenerators::UicParseContent(std::string const& absFilename, + std::string const& contentText) +{ + if (this->Verbose) { + this->LogInfo(cmQtAutoGen::UIC, "Checking: " + absFilename); + } + + std::vector includes; + // Extracte includes + { + const char* contentChars = contentText.c_str(); + if (strstr(contentChars, "ui_") != nullptr) { + while (this->UicRegExpInclude.find(contentChars)) { + includes.push_back(this->UicRegExpInclude.match(1)); + contentChars += this->UicRegExpInclude.end(); + } + } + } + + for (std::string const& includeString : includes) { + std::string uiInputFile; + if (!UicFindIncludedFile(uiInputFile, absFilename, includeString)) { + return false; + } + // Check if this file should be skipped + if (this->UicSkip(uiInputFile)) { + continue; + } + // Check if the job already exists + bool jobExists = false; + for (const auto& job : this->UicJobs) { + if ((job->SourceFile == uiInputFile) && + (job->IncludeString == includeString)) { + jobExists = true; + break; + } + } + if (!jobExists) { + auto job = cm::make_unique(); + job->SourceFile = uiInputFile; + job->BuildFileRel = this->AutogenIncludeDir; + job->BuildFileRel += includeString; + job->Includer = absFilename; + job->IncludeString = includeString; + this->UicJobs.push_back(std::move(job)); } } - return mocGenerated; + + return true; } bool cmQtAutoGenerators::UicFindIncludedFile(std::string& absFile, - const std::string& sourceFile, - const std::string& searchPath, - const std::string& searchFile) + std::string const& sourceFile, + std::string const& includeString) { bool success = false; - std::vector testFiles; + std::string searchFile = + cmSystemTools::GetFilenameWithoutLastExtension(includeString).substr(3); + searchFile += ".ui"; // Collect search paths list + std::vector testFiles; { - const std::string searchFileFull = searchPath + searchFile; + std::string const searchPath = SubDirPrefix(includeString); + + std::string searchFileFull; + if (!searchPath.empty()) { + searchFileFull = searchPath; + searchFileFull += searchFile; + } // Vicinity of the source { - const std::string sourcePath = SubDirPrefix(sourceFile); + std::string const sourcePath = SubDirPrefix(sourceFile); testFiles.push_back(sourcePath + searchFile); if (!searchPath.empty()) { testFiles.push_back(sourcePath + searchFileFull); @@ -1461,27 +1717,21 @@ bool cmQtAutoGenerators::UicFindIncludedFile(std::string& absFile, } // AUTOUIC search paths if (!this->UicSearchPaths.empty()) { - for (std::vector::const_iterator iit = - this->UicSearchPaths.begin(); - iit != this->UicSearchPaths.end(); ++iit) { - testFiles.push_back(*iit + "/" + searchFile); + for (std::string const& sPath : this->UicSearchPaths) { + testFiles.push_back((sPath + "/").append(searchFile)); } if (!searchPath.empty()) { - for (std::vector::const_iterator iit = - this->UicSearchPaths.begin(); - iit != this->UicSearchPaths.end(); ++iit) { - testFiles.push_back(*iit + "/" + searchFileFull); + for (std::string const& sPath : this->UicSearchPaths) { + testFiles.push_back((sPath + "/").append(searchFileFull)); } } } } // Search for the .ui file! - for (std::vector::const_iterator iit = testFiles.begin(); - iit != testFiles.end(); ++iit) { - const std::string& testFile = *iit; - if (cmsys::SystemTools::FileExists(testFile.c_str())) { - absFile = cmsys::SystemTools::GetRealPath(testFile); + for (std::string const& testFile : testFiles) { + if (cmSystemTools::FileExists(testFile.c_str())) { + absFile = cmSystemTools::GetRealPath(testFile); success = true; break; } @@ -1489,84 +1739,75 @@ bool cmQtAutoGenerators::UicFindIncludedFile(std::string& absFile, // Log error if (!success) { - std::ostringstream ost; - ost << "AutoUic: Error: " << Quoted(sourceFile) << "\n"; - ost << "Could not find " << Quoted(searchFile) << " in\n"; - for (std::vector::const_iterator iit = testFiles.begin(); - iit != testFiles.end(); ++iit) { - ost << " " << Quoted(*iit) << "\n"; + std::string emsg = "Could not find "; + emsg += cmQtAutoGen::Quoted(searchFile); + emsg += " in\n"; + for (std::string const& testFile : testFiles) { + emsg += " "; + emsg += cmQtAutoGen::Quoted(testFile); + emsg += "\n"; } - this->LogError(ost.str()); + this->LogFileError(cmQtAutoGen::UIC, sourceFile, emsg); } return success; } -bool cmQtAutoGenerators::UicGenerateAll( - const std::map >& uisIncluded) +bool cmQtAutoGenerators::UicGenerateAll() { if (!this->UicEnabled()) { return true; } - // single map with input / output names - std::map > sourceGenMap; + // Look for name collisions in included uic files { - // Collision lookup map - std::map testMap; - // Compile maps - for (std::map >::const_iterator sit = - uisIncluded.begin(); - sit != uisIncluded.end(); ++sit) { - const std::string& source(sit->first); - const std::vector& sourceIncs(sit->second); - // insert new source/destination map - std::map& uiGenMap = sourceGenMap[source]; - for (std::vector::const_iterator uit = sourceIncs.begin(); - uit != sourceIncs.end(); ++uit) { - // Remove ui_ from the begin filename by substr() - const std::string uiBasePath = SubDirPrefix(*uit); - const std::string uiBaseName = - cmsys::SystemTools::GetFilenameWithoutLastExtension(*uit).substr(3); - const std::string uiFileName = uiBaseName + ".ui"; - std::string uiInputFile; - if (UicFindIncludedFile(uiInputFile, source, uiBasePath, uiFileName)) { - std::string uiOutputFile = uiBasePath + "ui_" + uiBaseName + ".h"; - cmSystemTools::ReplaceString(uiOutputFile, "..", "__"); - uiGenMap[uiInputFile] = uiOutputFile; - testMap[uiInputFile] = uiOutputFile; - } else { - return false; - } + bool collision = false; + std::map> collisions; + for (auto const& job : this->UicJobs) { + auto& list = collisions[job->IncludeString]; + if (!list.empty()) { + collision = true; } - } - // look for name collisions - { - std::multimap collisions; - if (this->NameCollisionTest(testMap, collisions)) { - std::ostringstream ost; - ost << "AutoUic: Error: The same ui_NAME.h file will be generated " - "from different sources.\n" - "To avoid this error rename the source files.\n"; - this->LogErrorNameCollision(ost.str(), collisions); - return false; + list.push_back(job.get()); + } + if (collision) { + std::string emsg = + "Included uic files with the same name will be " + "generated from different sources.\n" + "Consider to\n" + " - add a directory prefix to a \"ui_.h\" include " + "(e.g \"sub/ui_.h\")\n" + " - rename the .ui file(s) and adjust the \"ui_.h\" " + "include(s)\n" + "Include conflicts\n" + "-----------------\n"; + const auto& colls = collisions; + for (auto const& coll : colls) { + if (coll.second.size() > 1) { + emsg += cmQtAutoGen::Quoted(coll.first); + emsg += " included in\n"; + for (const UicJob* job : coll.second) { + emsg += " - "; + emsg += cmQtAutoGen::Quoted(job->Includer); + emsg += "\n"; + } + emsg += "would be generated from\n"; + for (const UicJob* job : coll.second) { + emsg += " - "; + emsg += cmQtAutoGen::Quoted(job->SourceFile); + emsg += "\n"; + } + } } + this->LogError(cmQtAutoGen::UIC, emsg); + return false; } } - // generate ui files - for (std::map >::const_iterator it = - sourceGenMap.begin(); - it != sourceGenMap.end(); ++it) { - for (std::map::const_iterator sit = - it->second.begin(); - sit != it->second.end(); ++sit) { - if (!this->UicGenerateFile(it->first, sit->first, sit->second)) { - if (this->UicRunFailed) { - return false; - } - } + // Generate ui header files + for (const auto& item : this->UicJobs) { + if (!this->UicGenerateFile(*item)) { + return false; } } @@ -1574,71 +1815,100 @@ bool cmQtAutoGenerators::UicGenerateAll( } /** - * @return True if a uic file was created. False may indicate an error. + * @return True on success */ -bool cmQtAutoGenerators::UicGenerateFile(const std::string& realName, - const std::string& uiInputFile, - const std::string& uiOutputFile) +bool cmQtAutoGenerators::UicGenerateFile(const UicJob& uicJob) { - bool uicGenerated = false; - bool generateUic = this->UicSettingsChanged; + bool success = true; - const std::string uicFileRel = this->AutogenIncludeDir + uiOutputFile; - const std::string uicFileAbs = - cmSystemTools::CollapseCombinedPath(this->AutogenBuildDir, uicFileRel); + std::string const uicFileAbs = cmSystemTools::CollapseCombinedPath( + this->AutogenBuildDir, uicJob.BuildFileRel); - if (!generateUic) { - // Test if the source file is newer that the build file - generateUic = FileAbsentOrOlder(uicFileAbs, uiInputFile); + bool generate = false; + std::string generateReason; + if (!generate && !cmSystemTools::FileExists(uicFileAbs.c_str())) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(uicFileAbs); + generateReason += " from its source file "; + generateReason += cmQtAutoGen::Quoted(uicJob.SourceFile); + generateReason += " because it doesn't exist"; + } + generate = true; + } + if (!generate && this->UicSettingsChanged) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(uicFileAbs); + generateReason += " from "; + generateReason += cmQtAutoGen::Quoted(uicJob.SourceFile); + generateReason += " because the UIC settings changed"; + } + generate = true; + } + if (!generate) { + std::string error; + if (FileIsOlderThan(uicFileAbs, uicJob.SourceFile, &error)) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(uicFileAbs); + generateReason += " because it's older than its source file "; + generateReason += cmQtAutoGen::Quoted(uicJob.SourceFile); + } + generate = true; + } else { + if (!error.empty()) { + this->LogError(cmQtAutoGen::UIC, error); + success = false; + } + } } - if (generateUic) { + if (generate) { // Log - this->LogBold("Generating UIC header " + uicFileRel); + if (this->Verbose) { + this->LogBold("Generating UIC header " + uicJob.BuildFileRel); + this->LogInfo(cmQtAutoGen::UIC, generateReason); + } // Make sure the parent directory exists - if (this->MakeParentDirectory("AutoUic", uicFileAbs)) { + if (this->MakeParentDirectory(cmQtAutoGen::UIC, uicFileAbs)) { // Compose uic command std::vector cmd; cmd.push_back(this->UicExecutable); { std::vector allOpts = this->UicTargetOptions; - std::map::const_iterator optionIt = - this->UicOptions.find(uiInputFile); + auto optionIt = this->UicOptions.find(uicJob.SourceFile); if (optionIt != this->UicOptions.end()) { - std::vector fileOpts; - cmSystemTools::ExpandListArgument(optionIt->second, fileOpts); - UicMergeOptions(allOpts, fileOpts, (this->QtMajorVersion == "5")); + cmQtAutoGen::UicMergeOptions(allOpts, optionIt->second, + (this->QtMajorVersion == "5")); } cmd.insert(cmd.end(), allOpts.begin(), allOpts.end()); } cmd.push_back("-o"); cmd.push_back(uicFileAbs); - cmd.push_back(uiInputFile); + cmd.push_back(uicJob.SourceFile); std::string output; if (this->RunCommand(cmd, output)) { // Success - uicGenerated = true; } else { // Command failed { - std::ostringstream ost; - ost << "AutoUic: Error: uic process failed for\n"; - ost << Quoted(uicFileRel) << " needed by\n"; - ost << Quoted(realName) << "\n"; - ost << "AutoUic: Command:\n" << QuotedCommand(cmd) << "\n"; - ost << "AutoUic: Command output:\n" << output << "\n"; - this->LogError(ost.str()); + std::string emsg = "uic failed for\n "; + emsg += cmQtAutoGen::Quoted(uicJob.SourceFile); + emsg += "\nincluded by\n "; + emsg += cmQtAutoGen::Quoted(uicJob.Includer); + this->LogCommandError(cmQtAutoGen::UIC, emsg, cmd, output); } cmSystemTools::RemoveFile(uicFileAbs); - this->UicRunFailed = true; + success = false; } } else { // Parent directory creation failed - this->UicRunFailed = true; + success = false; } } - return uicGenerated; + return success; } bool cmQtAutoGenerators::RccGenerateAll() @@ -1647,322 +1917,375 @@ bool cmQtAutoGenerators::RccGenerateAll() return true; } - // generate single map with input / output names - std::map qrcGenMap; - { - const std::string qrcPrefix = "qrc_"; - const std::string qrcSuffix = this->ConfigSuffix + ".cpp"; - for (std::vector::const_iterator si = - this->RccSources.begin(); - si != this->RccSources.end(); ++si) { - const std::string ext = - cmsys::SystemTools::GetFilenameLastExtension(*si); - if (ext == ".qrc") { - qrcGenMap[*si] = this->ChecksumedPath(*si, qrcPrefix, qrcSuffix); - } - } - } - - // look for name collisions - { - std::multimap collisions; - if (this->NameCollisionTest(qrcGenMap, collisions)) { - std::ostringstream ost; - ost << "AutoRcc: Error: The same qrc_NAME.cpp file" - " will be generated from different sources.\n" - "To avoid this error rename the source .qrc files.\n"; - this->LogErrorNameCollision(ost.str(), collisions); + // Generate rcc files + for (const RccJob& rccJob : this->RccJobs) { + if (!this->RccGenerateFile(rccJob)) { return false; } } - - // generate qrc files - for (std::map::const_iterator si = - qrcGenMap.begin(); - si != qrcGenMap.end(); ++si) { - bool unique = FileNameIsUnique(si->first, qrcGenMap); - if (!this->RccGenerateFile(si->first, si->second, unique)) { - if (this->RccRunFailed) { - return false; - } - } - } return true; } /** - * @return True if a rcc file was created. False may indicate an error. + * @return True on success */ -bool cmQtAutoGenerators::RccGenerateFile(const std::string& rccInputFile, - const std::string& rccOutputFile, - bool unique_n) +bool cmQtAutoGenerators::RccGenerateFile(const RccJob& rccJob) { + bool success = true; bool rccGenerated = false; - bool generateRcc = this->RccSettingsChanged; - - const std::string rccBuildFile = - cmSystemTools::CollapseCombinedPath(this->AutogenBuildDir, rccOutputFile); - - if (!generateRcc) { - // Test if the resources list file is newer than build file - generateRcc = FileAbsentOrOlder(rccBuildFile, rccInputFile); - if (!generateRcc) { - // Acquire input file list - std::vector readFiles; - const std::vector* files = &this->RccInputs[rccInputFile]; - if (files->empty()) { - // Read input file list from qrc file - std::string error; - if (cmQtAutoGeneratorCommon::RccListInputs( - this->QtMajorVersion, this->RccExecutable, rccInputFile, - readFiles, &error)) { - files = &readFiles; - } else { - files = CM_NULLPTR; - this->LogError(error); - this->RccRunFailed = true; - } + + std::string rccFileAbs; + { + std::string suffix; + switch (this->MultiConfig) { + case cmQtAutoGen::SINGLE: + break; + case cmQtAutoGen::WRAP: + suffix = "_CMAKE"; + suffix += this->ConfigSuffix; + suffix += "_"; + break; + case cmQtAutoGen::FULL: + suffix = this->ConfigSuffix; + break; + } + rccFileAbs = cmQtAutoGen::AppendFilenameSuffix(rccJob.RccFile, suffix); + } + std::string const rccFileRel = cmSystemTools::RelativePath( + this->AutogenBuildDir.c_str(), rccFileAbs.c_str()); + + // Check if regeneration is required + bool generate = false; + std::string generateReason; + if (!cmSystemTools::FileExists(rccJob.QrcFile)) { + { + std::string error = "Could not find the file\n "; + error += cmQtAutoGen::Quoted(rccJob.QrcFile); + this->LogError(cmQtAutoGen::RCC, error); + } + success = false; + } + if (success && !generate && !cmSystemTools::FileExists(rccFileAbs.c_str())) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(rccFileAbs); + generateReason += " from its source file "; + generateReason += cmQtAutoGen::Quoted(rccJob.QrcFile); + generateReason += " because it doesn't exist"; + } + generate = true; + } + if (success && !generate && this->RccSettingsChanged) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(rccFileAbs); + generateReason += " from "; + generateReason += cmQtAutoGen::Quoted(rccJob.QrcFile); + generateReason += " because the RCC settings changed"; + } + generate = true; + } + if (success && !generate) { + std::string error; + if (FileIsOlderThan(rccFileAbs, rccJob.QrcFile, &error)) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(rccFileAbs); + generateReason += " because it is older than "; + generateReason += cmQtAutoGen::Quoted(rccJob.QrcFile); + } + generate = true; + } else { + if (!error.empty()) { + this->LogError(cmQtAutoGen::RCC, error); + success = false; + } + } + } + if (success && !generate) { + // Acquire input file list + std::vector readFiles; + std::vector const* files = nullptr; + if (!rccJob.Inputs.empty()) { + files = &rccJob.Inputs; + } else { + // Read input file list from qrc file + std::string error; + if (cmQtAutoGen::RccListInputs(this->QtMajorVersion, this->RccExecutable, + rccJob.QrcFile, readFiles, &error)) { + files = &readFiles; + } else { + this->LogFileError(cmQtAutoGen::RCC, rccJob.QrcFile, error); + success = false; } - // Test if any input file is newer than the build file - if (files != CM_NULLPTR) { - for (std::vector::const_iterator it = files->begin(); - it != files->end(); ++it) { - if (FileAbsentOrOlder(rccBuildFile, *it)) { - generateRcc = true; - break; + } + // Test if any input file is newer than the build file + if (files != nullptr) { + std::string error; + for (std::string const& resFile : *files) { + if (!cmSystemTools::FileExists(resFile.c_str())) { + error = "Could not find the file\n "; + error += cmQtAutoGen::Quoted(resFile); + error += "\nwhich is listed in\n "; + error += cmQtAutoGen::Quoted(rccJob.QrcFile); + break; + } + if (FileIsOlderThan(rccFileAbs, resFile, &error)) { + if (this->Verbose) { + generateReason = "Generating "; + generateReason += cmQtAutoGen::Quoted(rccFileAbs); + generateReason += " from "; + generateReason += cmQtAutoGen::Quoted(rccJob.QrcFile); + generateReason += " because it is older than "; + generateReason += cmQtAutoGen::Quoted(resFile); } + generate = true; + break; } + if (!error.empty()) { + break; + } + } + // Print error + if (!error.empty()) { + this->LogError(cmQtAutoGen::RCC, error); + success = false; } } } - if (generateRcc) { + // Regenerate on demand + if (generate) { // Log - this->LogBold("Generating RCC source " + rccOutputFile); + if (this->Verbose) { + this->LogBold("Generating RCC source " + rccFileRel); + this->LogInfo(cmQtAutoGen::RCC, generateReason); + } // Make sure the parent directory exists - if (this->MakeParentDirectory("AutoRcc", rccBuildFile)) { - // Compose symbol name - std::string symbolName = - cmsys::SystemTools::GetFilenameWithoutLastExtension(rccInputFile); - if (!unique_n) { - symbolName += "_"; - symbolName += FPathChecksum.getPart(rccInputFile); - } - // Replace '-' with '_'. The former is valid for - // file names but not for symbol names. - std::replace(symbolName.begin(), symbolName.end(), '-', '_'); - + if (this->MakeParentDirectory(cmQtAutoGen::RCC, rccFileAbs)) { // Compose rcc command std::vector cmd; cmd.push_back(this->RccExecutable); - { - std::map::const_iterator optionIt = - this->RccOptions.find(rccInputFile); - if (optionIt != this->RccOptions.end()) { - cmSystemTools::ExpandListArgument(optionIt->second, cmd); - } - } - cmd.push_back("-name"); - cmd.push_back(symbolName); + cmd.insert(cmd.end(), rccJob.Options.begin(), rccJob.Options.end()); cmd.push_back("-o"); - cmd.push_back(rccBuildFile); - cmd.push_back(rccInputFile); + cmd.push_back(rccFileAbs); + cmd.push_back(rccJob.QrcFile); std::string output; if (this->RunCommand(cmd, output)) { // Success rccGenerated = true; } else { - // Command failed { - std::ostringstream ost; - ost << "AutoRcc: Error: rcc process failed for\n"; - ost << Quoted(rccOutputFile) << "\n"; - ost << "AutoRcc: Command:\n" << QuotedCommand(cmd) << "\n"; - ost << "AutoRcc: Command output:\n" << output << "\n"; - this->LogError(ost.str()); + std::string emsg = "rcc failed for\n "; + emsg += cmQtAutoGen::Quoted(rccJob.QrcFile); + this->LogCommandError(cmQtAutoGen::RCC, emsg, cmd, output); } - cmSystemTools::RemoveFile(rccBuildFile); - this->RccRunFailed = true; + cmSystemTools::RemoveFile(rccFileAbs); + success = false; } } else { // Parent directory creation failed - this->RccRunFailed = true; + success = false; } } - return rccGenerated; -} - -void cmQtAutoGenerators::LogErrorNameCollision( - const std::string& message, - const std::multimap& collisions) const -{ - typedef std::multimap::const_iterator Iter; - std::ostringstream ost; - // Add message - if (!message.empty()) { - ost << message; - if (message[message.size() - 1] != '\n') { - ost << '\n'; + // Generate a wrapper source file on demand + if (success && (this->MultiConfig == cmQtAutoGen::WRAP)) { + // Wrapper file name + std::string const& wrapperFileAbs = rccJob.RccFile; + std::string const wrapperFileRel = cmSystemTools::RelativePath( + this->AutogenBuildDir.c_str(), wrapperFileAbs.c_str()); + // Wrapper file content + std::string content = "// This is an autogenerated configuration " + "wrapper file. Changes will be overwritten.\n" + "#include \""; + content += cmSystemTools::GetFilenameName(rccFileRel); + content += "\"\n"; + // Write content to file + if (this->FileDiffers(wrapperFileAbs, content)) { + // Write new wrapper file + if (this->Verbose) { + this->LogBold("Generating RCC wrapper " + wrapperFileRel); + } + if (!this->FileWrite(cmQtAutoGen::RCC, wrapperFileAbs, content)) { + this->LogFileError(cmQtAutoGen::RCC, wrapperFileAbs, + "rcc wrapper file writing failed"); + success = false; + } + } else if (rccGenerated) { + // Just touch the wrapper file + if (this->Verbose) { + this->LogInfo(cmQtAutoGen::RCC, + "Touching RCC wrapper " + wrapperFileRel); + } + cmSystemTools::Touch(wrapperFileAbs, false); } } - // Append collision list - for (Iter it = collisions.begin(); it != collisions.end(); ++it) { - ost << it->first << " : " << it->second << '\n'; - } - this->LogError(ost.str()); + + return success; } -void cmQtAutoGenerators::LogBold(const std::string& message) const +void cmQtAutoGenerators::LogBold(std::string const& message) const { cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue | cmsysTerminal_Color_ForegroundBold, message.c_str(), true, this->ColorOutput); } -void cmQtAutoGenerators::LogInfo(const std::string& message) const +void cmQtAutoGenerators::LogInfo(cmQtAutoGen::Generator genType, + std::string const& message) const { - std::string msg(message); - if (!msg.empty()) { - if (msg[msg.size() - 1] != '\n') { - msg.push_back('\n'); - } - cmSystemTools::Stdout(msg.c_str(), msg.size()); + std::string msg = cmQtAutoGen::GeneratorName(genType); + msg += ": "; + msg += message; + if (msg.back() != '\n') { + msg.push_back('\n'); } + cmSystemTools::Stdout(msg.c_str(), msg.size()); } -void cmQtAutoGenerators::LogWarning(const std::string& message) const +void cmQtAutoGenerators::LogWarning(cmQtAutoGen::Generator genType, + std::string const& message) const { - std::string msg(message); - if (!msg.empty()) { - if (msg[msg.size() - 1] != '\n') { - msg.push_back('\n'); - } - // Append empty line + std::string msg = cmQtAutoGen::GeneratorName(genType); + msg += " warning:"; + if (message.find('\n') == std::string::npos) { + // Single line message + msg.push_back(' '); + } else { + // Multi line message + msg.push_back('\n'); + } + // Message + msg += message; + if (msg.back() != '\n') { msg.push_back('\n'); - cmSystemTools::Stdout(msg.c_str(), msg.size()); } + msg.push_back('\n'); + cmSystemTools::Stdout(msg.c_str(), msg.size()); } -void cmQtAutoGenerators::LogError(const std::string& message) const +void cmQtAutoGenerators::LogFileWarning(cmQtAutoGen::Generator genType, + std::string const& filename, + std::string const& message) const { - std::string msg(message); - if (!msg.empty()) { - if (msg[msg.size() - 1] != '\n') { - msg.push_back('\n'); - } - // Append empty line - msg.push_back('\n'); - cmSystemTools::Stderr(msg.c_str(), msg.size()); - } + std::string msg = " "; + msg += cmQtAutoGen::Quoted(filename); + msg.push_back('\n'); + // Message + msg += message; + this->LogWarning(genType, msg); } -/** - * @brief Collects name collisions as output/input pairs - * @return True if there were collisions - */ -bool cmQtAutoGenerators::NameCollisionTest( - const std::map& genFiles, - std::multimap& collisions) const +void cmQtAutoGenerators::LogError(cmQtAutoGen::Generator genType, + std::string const& message) const { - typedef std::map::const_iterator Iter; - typedef std::map::value_type VType; - for (Iter ait = genFiles.begin(); ait != genFiles.end(); ++ait) { - bool first_match(true); - for (Iter bit = (++Iter(ait)); bit != genFiles.end(); ++bit) { - if (ait->second == bit->second) { - if (first_match) { - if (collisions.find(ait->second) != collisions.end()) { - // We already know of this collision from before - break; - } - collisions.insert(VType(ait->second, ait->first)); - first_match = false; - } - collisions.insert(VType(bit->second, bit->first)); - } - } + std::string msg; + msg.push_back('\n'); + msg += HeadLine(cmQtAutoGen::GeneratorName(genType) + " error"); + // Message + msg += message; + if (msg.back() != '\n') { + msg.push_back('\n'); } + msg.push_back('\n'); + cmSystemTools::Stderr(msg.c_str(), msg.size()); +} - return !collisions.empty(); +void cmQtAutoGenerators::LogFileError(cmQtAutoGen::Generator genType, + std::string const& filename, + std::string const& message) const +{ + std::string emsg = " "; + emsg += cmQtAutoGen::Quoted(filename); + emsg += '\n'; + // Message + emsg += message; + this->LogError(genType, emsg); } -/** - * @brief Generates a file path based on the checksum of the source file path - * @return The path - */ -std::string cmQtAutoGenerators::ChecksumedPath( - const std::string& sourceFile, const std::string& basePrefix, - const std::string& baseSuffix) const +void cmQtAutoGenerators::LogCommandError( + cmQtAutoGen::Generator genType, std::string const& message, + std::vector const& command, std::string const& output) const { - std::string res = FPathChecksum.getPart(sourceFile); - res += "/"; - res += basePrefix; - res += cmsys::SystemTools::GetFilenameWithoutLastExtension(sourceFile); - res += baseSuffix; - return res; + std::string msg; + msg.push_back('\n'); + msg += HeadLine(cmQtAutoGen::GeneratorName(genType) + " subprocess error"); + msg += message; + if (msg.back() != '\n') { + msg.push_back('\n'); + } + msg.push_back('\n'); + msg += HeadLine("Command"); + msg += QuotedCommand(command); + if (msg.back() != '\n') { + msg.push_back('\n'); + } + msg.push_back('\n'); + msg += HeadLine("Output"); + msg += output; + if (msg.back() != '\n') { + msg.push_back('\n'); + } + msg.push_back('\n'); + cmSystemTools::Stderr(msg.c_str(), msg.size()); } /** * @brief Generates the parent directory of the given file on demand * @return True on success */ -bool cmQtAutoGenerators::MakeParentDirectory(const char* logPrefix, - const std::string& filename) const +bool cmQtAutoGenerators::MakeParentDirectory(cmQtAutoGen::Generator genType, + std::string const& filename) const { bool success = true; - const std::string dirName = cmSystemTools::GetFilenamePath(filename); + std::string const dirName = cmSystemTools::GetFilenamePath(filename); if (!dirName.empty()) { - success = cmsys::SystemTools::MakeDirectory(dirName); - if (!success) { - std::string error = logPrefix; - error += ": Error: Parent directory creation failed for "; - error += Quoted(filename); - this->LogError(error); + if (!cmSystemTools::MakeDirectory(dirName)) { + this->LogFileError(genType, filename, + "Could not create parent directory"); + success = false; } } return success; } -bool cmQtAutoGenerators::FileDiffers(const std::string& filename, - const std::string& content) +bool cmQtAutoGenerators::FileDiffers(std::string const& filename, + std::string const& content) { bool differs = true; { std::string oldContents; - if (ReadAll(oldContents, filename)) { + if (ReadFile(oldContents, filename)) { differs = (oldContents != content); } } return differs; } -bool cmQtAutoGenerators::FileWrite(const char* logPrefix, - const std::string& filename, - const std::string& content) +bool cmQtAutoGenerators::FileWrite(cmQtAutoGen::Generator genType, + std::string const& filename, + std::string const& content) { std::string error; // Make sure the parent directory exists - if (this->MakeParentDirectory(logPrefix, filename)) { + if (this->MakeParentDirectory(genType, filename)) { cmsys::ofstream outfile; - outfile.open(filename.c_str(), std::ios::trunc); + outfile.open(filename.c_str(), + (std::ios::out | std::ios::binary | std::ios::trunc)); if (outfile) { outfile << content; // Check for write errors if (!outfile.good()) { - error = logPrefix; - error += ": Error writing "; - error += Quoted(filename); + error = "File writing failed"; } } else { - error = logPrefix; - error = ": Error opening "; - error += Quoted(filename); + error = "Opening file for writing failed"; } } if (!error.empty()) { - this->LogError(error); + this->LogFileError(genType, filename, error); return false; } return true; @@ -1972,18 +2295,19 @@ bool cmQtAutoGenerators::FileWrite(const char* logPrefix, * @brief Runs a command and returns true on success * @return True on success */ -bool cmQtAutoGenerators::RunCommand(const std::vector& command, - std::string& output, bool verbose) const +bool cmQtAutoGenerators::RunCommand(std::vector const& command, + std::string& output) const { // Log command if (this->Verbose) { - this->LogInfo(QuotedCommand(command)); + std::string qcmd = QuotedCommand(command); + qcmd.push_back('\n'); + cmSystemTools::Stdout(qcmd.c_str(), qcmd.size()); } // Execute command int retVal = 0; bool res = cmSystemTools::RunSingleCommand( - command, &output, &output, &retVal, CM_NULLPTR, - verbose ? cmSystemTools::OUTPUT_MERGE : cmSystemTools::OUTPUT_NONE); + command, &output, &output, &retVal, nullptr, cmSystemTools::OUTPUT_NONE); return (res && (retVal == 0)); } @@ -1993,71 +2317,16 @@ bool cmQtAutoGenerators::RunCommand(const std::vector& command, * @return True on success */ bool cmQtAutoGenerators::FindHeader(std::string& header, - const std::string& testBasePath) const + std::string const& testBasePath) const { - for (std::vector::const_iterator ext = - this->HeaderExtensions.begin(); - ext != this->HeaderExtensions.end(); ++ext) { + for (std::string const& ext : this->HeaderExtensions) { std::string testFilePath(testBasePath); - testFilePath += '.'; - testFilePath += (*ext); - if (cmsys::SystemTools::FileExists(testFilePath.c_str())) { + testFilePath.push_back('.'); + testFilePath += ext; + if (cmSystemTools::FileExists(testFilePath.c_str())) { header = testFilePath; return true; } } return false; } - -std::string cmQtAutoGenerators::MocFindHeader( - const std::string& sourcePath, const std::string& includeBase) const -{ - std::string header; - // Search in vicinity of the source - if (!this->FindHeader(header, sourcePath + includeBase)) { - // Search in include directories - for (std::vector::const_iterator iit = - this->MocIncludePaths.begin(); - iit != this->MocIncludePaths.end(); ++iit) { - const std::string fullPath = ((*iit) + '/' + includeBase); - if (FindHeader(header, fullPath)) { - break; - } - } - } - // Sanitize - if (!header.empty()) { - header = cmsys::SystemTools::GetRealPath(header); - } - return header; -} - -bool cmQtAutoGenerators::MocFindIncludedFile( - std::string& absFile, const std::string& sourcePath, - const std::string& includeString) const -{ - bool success = false; - // Search in vicinity of the source - { - std::string testPath = sourcePath; - testPath += includeString; - if (cmsys::SystemTools::FileExists(testPath.c_str())) { - absFile = cmsys::SystemTools::GetRealPath(testPath); - success = true; - } - } - // Search in include directories - if (!success) { - for (std::vector::const_iterator iit = - this->MocIncludePaths.begin(); - iit != this->MocIncludePaths.end(); ++iit) { - const std::string fullPath = ((*iit) + '/' + includeString); - if (cmsys::SystemTools::FileExists(fullPath.c_str())) { - absFile = cmsys::SystemTools::GetRealPath(fullPath); - success = true; - break; - } - } - } - return success; -} diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 337aa17fd..a7bb53840 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -6,160 +6,194 @@ #include "cmConfigure.h" // IWYU pragma: keep #include "cmFilePathChecksum.h" +#include "cmQtAutoGen.h" #include "cmsys/RegularExpression.hxx" #include +#include // IWYU pragma: keep #include #include -#include #include class cmMakefile; class cmQtAutoGenerators { + CM_DISABLE_COPY(cmQtAutoGenerators) public: cmQtAutoGenerators(); - bool Run(const std::string& targetDirectory, const std::string& config); + bool Run(std::string const& targetDirectory, std::string const& config); private: // -- Types - /// @brief Used to extract additional dependencies from content text - struct MocDependFilter + /// @brief Search key plus regular expression pair + struct KeyRegExp { - std::string key; - cmsys::RegularExpression regExp; + KeyRegExp() = default; + + KeyRegExp(const char* key, const char* regExp) + : Key(key) + , RegExp(regExp) + { + } + + KeyRegExp(std::string const& key, std::string const& regExp) + : Key(key) + , RegExp(regExp) + { + } + + std::string Key; + cmsys::RegularExpression RegExp; }; - typedef std::pair MocMacroFilter; - // -- Configuration - bool MocDependFilterPush(const std::string& key, const std::string& regExp); - bool ReadAutogenInfoFile(cmMakefile* makefile, - const std::string& targetDirectory, - const std::string& config); + /// @brief Source file job + struct SourceJob + { + bool Moc = false; + bool Uic = false; + }; - bool MocEnabled() const { return !this->MocExecutable.empty(); } - bool UicEnabled() const { return !this->UicExecutable.empty(); } - bool RccEnabled() const { return !this->RccExecutable.empty(); } + /// @brief MOC job + struct MocJobAuto + { + std::string SourceFile; + std::string BuildFileRel; + std::set Depends; + }; + + /// @brief MOC job + struct MocJobIncluded : MocJobAuto + { + bool DependsValid = false; + std::string Includer; + std::string IncludeString; + }; + + /// @brief UIC job + struct UicJob + { + std::string SourceFile; + std::string BuildFileRel; + std::string Includer; + std::string IncludeString; + }; + + /// @brief RCC job + struct RccJob + { + std::string QrcFile; + std::string RccFile; + std::vector Options; + std::vector Inputs; + }; + + // -- Initialization + bool InitInfoFile(cmMakefile* makefile, std::string const& targetDirectory, + std::string const& config); // -- Settings file void SettingsFileRead(cmMakefile* makefile); bool SettingsFileWrite(); - - bool AnySettingsChanged() const + bool SettingsChanged() const { return (this->MocSettingsChanged || this->RccSettingsChanged || this->UicSettingsChanged); } - // -- Init and run - void Init(cmMakefile* makefile); - bool RunAutogen(); - - // -- Content analysis - bool MocRequired(const std::string& contentText, - std::string* macroName = CM_NULLPTR); - void MocFindDepends( - const std::string& absFilename, const std::string& contentText, - std::map >& mocDepends); - - bool MocSkip(const std::string& absFilename) const; - bool UicSkip(const std::string& absFilename) const; - - bool ParseSourceFile( - const std::string& absFilename, - std::map& mocsIncluded, - std::map >& mocDepends, - std::map >& includedUis, - bool relaxed); - - void SearchHeadersForSourceFile(const std::string& absFilename, - std::set& mocHeaderFiles, - std::set& uicHeaderFiles) const; - - bool ParseHeaders( - const std::set& mocHeaderFiles, - const std::set& uicHeaderFiles, - const std::map& mocsIncluded, - std::map& mocsNotIncluded, - std::map >& mocDepends, - std::map >& includedUis); - - void UicParseContent( - const std::string& fileName, const std::string& contentText, - std::map >& includedUis); - - bool MocParseSourceContent( - const std::string& absFilename, const std::string& contentText, - std::map& mocsIncluded, - std::map >& mocDepends, bool relaxed); - - void MocParseHeaderContent( - const std::string& absFilename, const std::string& contentText, - std::map& mocsNotIncluded, - std::map >& mocDepends); - - // -- Moc file generation - bool MocGenerateAll( - const std::map& mocsIncluded, - const std::map& mocsNotIncluded, - const std::map >& mocDepends); - bool MocGenerateFile( - const std::string& sourceFile, const std::string& mocFileName, - const std::map >& mocDepends, - bool included); - - // -- Uic file generation - bool UicFindIncludedFile(std::string& absFile, const std::string& sourceFile, - const std::string& searchPath, - const std::string& searchFile); - bool UicGenerateAll( - const std::map >& includedUis); - bool UicGenerateFile(const std::string& realName, - const std::string& uiInputFile, - const std::string& uiOutputFile); - - // -- Rcc file generation + // -- Central processing + bool Process(); + + // -- Source parsing + bool ParseSourceFile(std::string const& absFilename, const SourceJob& job); + bool ParseHeaderFile(std::string const& absFilename, const SourceJob& job); + bool ParsePostprocess(); + + // -- Moc + bool MocEnabled() const { return !this->MocExecutable.empty(); } + bool MocSkip(std::string const& absFilename) const; + bool MocRequired(std::string const& contentText, + std::string* macroName = nullptr); + // Moc strings + std::string MocStringMacros() const; + std::string MocStringHeaders(std::string const& fileBase) const; + std::string MocFindIncludedHeader(std::string const& sourcePath, + std::string const& includeBase) const; + bool MocFindIncludedFile(std::string& absFile, std::string const& sourceFile, + std::string const& includeString) const; + // Moc depends + bool MocDependFilterPush(std::string const& key, std::string const& regExp); + void MocFindDepends(std::string const& absFilename, + std::string const& contentText, + std::set& depends); + // Moc + bool MocParseSourceContent(std::string const& absFilename, + std::string const& contentText); + void MocParseHeaderContent(std::string const& absFilename, + std::string const& contentText); + + bool MocGenerateAll(); + bool MocGenerateFile(const MocJobAuto& mocJob, bool* generated = nullptr); + + // -- Uic + bool UicEnabled() const { return !this->UicExecutable.empty(); } + bool UicSkip(std::string const& absFilename) const; + bool UicParseContent(std::string const& fileName, + std::string const& contentText); + bool UicFindIncludedFile(std::string& absFile, std::string const& sourceFile, + std::string const& includeString); + bool UicGenerateAll(); + bool UicGenerateFile(const UicJob& uicJob); + + // -- Rcc + bool RccEnabled() const { return !this->RccExecutable.empty(); } bool RccGenerateAll(); - bool RccGenerateFile(const std::string& qrcInputFile, - const std::string& qrcOutputFile, bool unique_n); - - // -- Logging - void LogErrorNameCollision( - const std::string& message, - const std::multimap& collisions) const; - void LogBold(const std::string& message) const; - void LogInfo(const std::string& message) const; - void LogWarning(const std::string& message) const; - void LogError(const std::string& message) const; - void LogCommand(const std::vector& command) const; + bool RccGenerateFile(const RccJob& rccJob); + + // -- Log info + void LogBold(std::string const& message) const; + void LogInfo(cmQtAutoGen::Generator genType, + std::string const& message) const; + // -- Log warning + void LogWarning(cmQtAutoGen::Generator genType, + std::string const& message) const; + void LogFileWarning(cmQtAutoGen::Generator genType, + std::string const& filename, + std::string const& message) const; + // -- Log error + void LogError(cmQtAutoGen::Generator genType, + std::string const& message) const; + void LogFileError(cmQtAutoGen::Generator genType, + std::string const& filename, + std::string const& message) const; + void LogCommandError(cmQtAutoGen::Generator genType, + std::string const& message, + std::vector const& command, + std::string const& output) const; // -- Utility - bool NameCollisionTest( - const std::map& genFiles, - std::multimap& collisions) const; - std::string ChecksumedPath(const std::string& sourceFile, - const std::string& basePrefix, - const std::string& baseSuffix) const; - bool MakeParentDirectory(const char* logPrefix, - const std::string& filename) const; - bool FileDiffers(const std::string& filename, const std::string& content); - bool FileWrite(const char* logPrefix, const std::string& filename, - const std::string& content); - - bool RunCommand(const std::vector& command, std::string& output, - bool verbose = true) const; - - bool FindHeader(std::string& header, const std::string& testBasePath) const; - - std::string MocFindHeader(const std::string& sourcePath, - const std::string& includeBase) const; - bool MocFindIncludedFile(std::string& absFile, const std::string& sourceFile, - const std::string& includeString) const; + bool MakeParentDirectory(cmQtAutoGen::Generator genType, + std::string const& filename) const; + bool FileDiffers(std::string const& filename, std::string const& content); + bool FileWrite(cmQtAutoGen::Generator genType, std::string const& filename, + std::string const& content); + bool FindHeader(std::string& header, std::string const& testBasePath) const; + bool RunCommand(std::vector const& command, + std::string& output) const; // -- Meta + std::string InfoFile; std::string ConfigSuffix; + cmQtAutoGen::MultiConfig MultiConfig; + // -- Settings + bool IncludeProjectDirsBefore; + bool Verbose; + bool ColorOutput; + std::string SettingsFile; + std::string SettingsStringMoc; + std::string SettingsStringUic; + std::string SettingsStringRcc; // -- Directories std::string ProjectSourceDir; std::string ProjectBinaryDir; @@ -169,27 +203,19 @@ private: std::string AutogenIncludeDir; // -- Qt environment std::string QtMajorVersion; + std::string QtMinorVersion; std::string MocExecutable; std::string UicExecutable; std::string RccExecutable; // -- File lists - std::vector Sources; - std::vector Headers; + std::map HeaderJobs; + std::map SourceJobs; std::vector HeaderExtensions; - cmFilePathChecksum FPathChecksum; - // -- Settings - bool IncludeProjectDirsBefore; - bool Verbose; - bool ColorOutput; - std::string SettingsFile; - std::string SettingsStringMoc; - std::string SettingsStringUic; - std::string SettingsStringRcc; + cmFilePathChecksum FilePathChecksum; // -- Moc bool MocSettingsChanged; bool MocPredefsChanged; bool MocRelaxedMode; - bool MocRunFailed; std::string MocCompFileRel; std::string MocCompFileAbs; std::string MocPredefsFileRel; @@ -199,24 +225,24 @@ private: std::vector MocIncludes; std::vector MocDefinitions; std::vector MocOptions; + std::vector MocAllOptions; std::vector MocPredefsCmd; - std::vector MocDependFilters; - MocMacroFilter MocMacroFilters[2]; + std::vector MocDependFilters; + std::vector MocMacroFilters; cmsys::RegularExpression MocRegExpInclude; + std::vector> MocJobsIncluded; + std::vector> MocJobsAuto; // -- Uic bool UicSettingsChanged; - bool UicRunFailed; std::vector UicSkipList; std::vector UicTargetOptions; - std::map UicOptions; + std::map> UicOptions; std::vector UicSearchPaths; cmsys::RegularExpression UicRegExpInclude; + std::vector> UicJobs; // -- Rcc bool RccSettingsChanged; - bool RccRunFailed; - std::vector RccSources; - std::map RccOptions; - std::map > RccInputs; + std::vector RccJobs; }; #endif diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx index 5364f76f4..112be4d37 100644 --- a/Source/cmRST.cxx +++ b/Source/cmRST.cxx @@ -86,7 +86,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 +101,7 @@ void cmRST::ProcessModule(std::istream& is) this->ProcessLine(line.substr(2)); continue; } - rst = ""; + rst.clear(); this->Reset(); this->OutputLinePending = true; } @@ -292,9 +292,7 @@ std::string cmRST::ReplaceSubstitutions(std::string const& line) void cmRST::OutputMarkupLines(bool inlineMarkup) { - for (std::vector::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 +345,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::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); diff --git a/Source/cmRemoveCommand.cxx b/Source/cmRemoveCommand.cxx index 1db84414a..bb14e687d 100644 --- a/Source/cmRemoveCommand.cxx +++ b/Source/cmRemoveCommand.cxx @@ -37,10 +37,10 @@ bool cmRemoveCommand::InitialPass(std::vector const& args, // 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 +49,7 @@ bool cmRemoveCommand::InitialPass(std::vector 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmRemoveDefinitionsCommand.cxx b/Source/cmRemoveDefinitionsCommand.cxx index f5fe2dfb7..8311b4b2f 100644 --- a/Source/cmRemoveDefinitionsCommand.cxx +++ b/Source/cmRemoveDefinitionsCommand.cxx @@ -15,9 +15,8 @@ bool cmRemoveDefinitionsCommand::InitialPass( return true; } - for (std::vector::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.c_str()); } 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 #include @@ -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 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmScriptGenerator.cxx b/Source/cmScriptGenerator.cxx index 753a1ba6f..2cae71436 100644 --- a/Source/cmScriptGenerator.cxx +++ b/Source/cmScriptGenerator.cxx @@ -10,7 +10,7 @@ cmScriptGenerator::cmScriptGenerator( : RuntimeConfigVariable(config_var) , Configurations(configurations) , ConfigurationName("") - , ConfigurationTypes(CM_NULLPTR) + , ConfigurationTypes(nullptr) , ActionsPerConfig(false) { } @@ -26,8 +26,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 +69,10 @@ std::string cmScriptGenerator::CreateConfigTest( result += this->RuntimeConfigVariable; result += "}\" MATCHES \"^("; const char* sep = ""; - for (std::vector::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 +122,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::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 +160,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::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..c8fed1950 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 #include diff --git a/Source/cmSearchPath.cxx b/Source/cmSearchPath.cxx index 0df6e0c06..a40c98706 100644 --- a/Source/cmSearchPath.cxx +++ b/Source/cmSearchPath.cxx @@ -27,10 +27,9 @@ void cmSearchPath::ExtractWithout(const std::set& ignore, if (clear) { outPaths.clear(); } - for (std::vector::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 +41,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 outPaths; @@ -69,24 +68,22 @@ void cmSearchPath::AddUserPath(const std::string& path) } // Process them all from the current directory - for (std::vector::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()); } } 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 expanded; cmSystemTools::ExpandListArgument(value, expanded); - for (std::vector::const_iterator p = expanded.begin(); - p != expanded.end(); ++p) { - this->AddPathInternal(*p, + for (std::string const& p : expanded) { + this->AddPathInternal(p, this->FC->Makefile->GetCurrentSourceDirectory()); } } @@ -96,15 +93,14 @@ void cmSearchPath::AddEnvPath(const std::string& variable) { std::vector expanded; cmSystemTools::GetPath(expanded, variable.c_str()); - for (std::vector::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)) { @@ -142,33 +138,31 @@ void cmSearchPath::AddSuffixes(const std::vector& suffixes) inPaths.swap(this->Paths); this->Paths.reserve(inPaths.size() * (suffixes.size() + 1)); - for (std::vector::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; + std::string p = inPath; if (!p.empty() && *p.rbegin() != '/') { p += "/"; } // Combine with all the suffixes - for (std::vector::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(inPath); } } void cmSearchPath::AddPrefixPaths(const std::vector& paths, const char* base) { - assert(this->FC != CM_NULLPTR); + assert(this->FC != nullptr); // default for programs std::string subdir = "bin"; @@ -178,12 +172,11 @@ void cmSearchPath::AddPrefixPaths(const std::vector& 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::const_iterator p = paths.begin(); - p != paths.end(); ++p) { - std::string dir = *p; + for (std::string const& path : paths) { + std::string dir = path; if (!subdir.empty() && !dir.empty() && *dir.rbegin() != '/') { dir += "/"; } @@ -201,15 +194,15 @@ void cmSearchPath::AddPrefixPaths(const std::vector& 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); diff --git a/Source/cmSearchPath.h b/Source/cmSearchPath.h index 932022aa1..fd0c7c52e 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 #include @@ -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& GetPaths() const { return this->Paths; } @@ -42,8 +42,8 @@ public: protected: void AddPrefixPaths(const std::vector& paths, - const char* base = CM_NULLPTR); - void AddPathInternal(const std::string& path, const char* base = CM_NULLPTR); + const char* base = nullptr); + void AddPathInternal(const std::string& path, const char* base = nullptr); cmFindCommon* FC; std::vector 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::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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index 7fc6ed755..e923c228a 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -2,7 +2,9 @@ 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 "cmServerDictionary.h" #include "cmServerProtocol.h" #include "cmSystemTools.h" @@ -14,8 +16,24 @@ #include #include #include +#include +#include #include +void on_signal(uv_signal_t* signal, int signum) +{ + auto conn = reinterpret_cast(signal->data); + conn->OnSignal(signum); +} + +static void on_walk_to_shutdown(uv_handle_t* handle, void* arg) +{ + (void)arg; + if (!uv_is_closing(handle)) { + uv_close(handle, &cmEventBasedConnection::on_close); + } +} + class cmServer::DebugInfo { public: @@ -30,59 +48,46 @@ 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; - } - 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 debug; Json::Value debugValue = value["debug"]; if (!debugValue.isNull()) { - debug = std::make_unique(); + debug = cm::make_unique(); 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; } @@ -91,15 +96,18 @@ void cmServer::PopOne() if (this->Protocol) { this->Protocol->CMakeInstance()->SetProgressCallback( reportProgress, const_cast(&request)); - this->WriteResponse(this->Protocol->Process(request), debug.get()); + 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 +123,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,13 +142,7 @@ 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) @@ -216,7 +218,7 @@ cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request) 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,16 +234,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 +{ + uv_rwlock_rdlock(&ConnectionsMutex); + for (auto& connection : this->Connections) { + WriteJsonObject(connection.get(), jsonValue, debug); + } + uv_rwlock_rdunlock(&ConnectionsMutex); +} + +void cmServer::WriteJsonObject(cmConnection* connection, + const Json::Value& jsonValue, + const DebugInfo* debug) const { Json::FastWriter writer; @@ -272,8 +285,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 +323,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 +343,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 +355,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 +371,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 +385,188 @@ 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(GetLoop()); +} + +void cmServer::StartShutDown() +{ + if (fileMonitor) { + fileMonitor->StopMonitoring(); + fileMonitor.reset(); + } + cmServerBase::StartShutDown(); +} + +static void __start_thread(void* arg) +{ + auto server = reinterpret_cast(arg); + std::string error; + bool success = server->Serve(&error); + if (!success || error.empty() == false) { + std::cerr << "Error during serve: " << error << std::endl; + } +} + +static void __shutdownThread(uv_async_t* arg) +{ + auto server = reinterpret_cast(arg->data); + on_walk_to_shutdown(reinterpret_cast(arg), nullptr); + server->StartShutDown(); +} + +bool cmServerBase::StartServeThread() +{ + ServeThreadRunning = true; + uv_async_init(&Loop, &this->ShutdownSignal, __shutdownThread); + this->ShutdownSignal.data = this; + uv_thread_create(&ServeThread, __start_thread, this); + return true; +} + +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(); + + uv_signal_init(&Loop, &this->SIGINTHandler); + uv_signal_init(&Loop, &this->SIGHUPHandler); + + this->SIGINTHandler.data = this; + this->SIGHUPHandler.data = this; + + uv_signal_start(&this->SIGINTHandler, &on_signal, SIGINT); + uv_signal_start(&this->SIGHUPHandler, &on_signal, SIGHUP); + + OnServeStart(); + + { + uv_rwlock_rdlock(&ConnectionsMutex); + for (auto& connection : Connections) { + if (!connection->OnServeStart(errorMessage)) { + uv_rwlock_rdunlock(&ConnectionsMutex); + return false; + } + } + uv_rwlock_rdunlock(&ConnectionsMutex); + } + + 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; + } + + ServeThreadRunning = false; + return true; +} + +void cmServerBase::OnConnected(cmConnection*) +{ +} + +void cmServerBase::OnServeStart() +{ +} + +void cmServerBase::StartShutDown() +{ + if (!uv_is_closing( + reinterpret_cast(&this->SIGINTHandler))) { + uv_signal_stop(&this->SIGINTHandler); + } + + if (!uv_is_closing( + reinterpret_cast(&this->SIGHUPHandler))) { + uv_signal_stop(&this->SIGHUPHandler); + } + + { + uv_rwlock_wrlock(&ConnectionsMutex); + for (auto& connection : Connections) { + connection->OnConnectionShuttingDown(); + } + Connections.clear(); + uv_rwlock_wrunlock(&ConnectionsMutex); + } + + 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; + assert(err == 0); + + err = uv_rwlock_init(&ConnectionsMutex); + assert(err == 0); + + AddNewConnection(connection); +} + +cmServerBase::~cmServerBase() +{ + + if (ServeThreadRunning) { + uv_async_send(&this->ShutdownSignal); + uv_thread_join(&ServeThread); + } + + uv_loop_close(&Loop); + uv_rwlock_destroy(&ConnectionsMutex); +} + +void cmServerBase::AddNewConnection(cmConnection* ownedConnection) +{ + uv_rwlock_wrlock(&ConnectionsMutex); + Connections.emplace_back(ownedConnection); + uv_rwlock_wrunlock(&ConnectionsMutex); + ownedConnection->SetServer(this); +} + +uv_loop_t* cmServerBase::GetLoop() +{ + return &Loop; +} + +void cmServerBase::OnDisconnect(cmConnection* pConnection) +{ + auto pred = [pConnection](const std::unique_ptr& m) { + return m.get() == pConnection; + }; + uv_rwlock_wrlock(&ConnectionsMutex); + Connections.erase( + std::remove_if(Connections.begin(), Connections.end(), pred), + Connections.end()); + uv_rwlock_wrunlock(&ConnectionsMutex); + if (Connections.empty()) { + StartShutDown(); + } } diff --git a/Source/cmServer.h b/Source/cmServer.h index b8140504c..15fd2baee 100644 --- a/Source/cmServer.h +++ b/Source/cmServer.h @@ -2,31 +2,98 @@ 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_uv.h" +#include // IWYU pragma: keep #include #include +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 +{ +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 OnDisconnect(cmConnection* pConnection); + +protected: + mutable uv_rwlock_t ConnectionsMutex; + std::vector> Connections; + + bool ServeThreadRunning = false; + uv_thread_t ServeThread; + uv_async_t 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; + + uv_signal_t SIGINTHandler; + uv_signal_t SIGHUPHandler; +}; + +class cmServer : public cmServerBase { CM_DISABLE_COPY(cmServer) public: class DebugInfo; - cmServer(cmServerConnection* conn, bool supportExperimental); - ~cmServer(); + cmServer(cmConnection* conn, bool supportExperimental); + ~cmServer() override; - bool Serve(std::string* errorMessage); + bool Serve(std::string* errorMessage) override; cmFileMonitor* FileMonitor() const; @@ -34,9 +101,20 @@ private: void RegisterProtocol(cmServerProtocol* protocol); // Callbacks from cmServerConnection: - void PopOne(); - void QueueRequest(const std::string& request); + void ProcessRequest(cmConnection* connection, + const std::string& request) override; + std::shared_ptr fileMonitor; + +public: + void OnServeStart() override; + + void StartShutDown() override; + +public: + void OnConnected(cmConnection* connection) override; + +private: static void reportProgress(const char* msg, float progress, void* data); static void reportMessage(const char* msg, const char* title, bool& cancel, void* data); @@ -44,50 +122,34 @@ private: // 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& protocols, int major, int minor); - cmServerConnection* Connection = nullptr; const bool SupportExperimental; cmServerProtocol* Protocol = nullptr; std::vector SupportedProtocols; - std::vector 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..44af75f82 100644 --- a/Source/cmServerConnection.cxx +++ b/Source/cmServerConnection.cxx @@ -2,376 +2,193 @@ 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" +#ifdef _WIN32 +#include "io.h" +#else +#include +#endif +#include -#include -#include - -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(suggested_size)); } -void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) +void cmStdIoConnection::SetupStream(uv_stream_t*& stream, int file_id) { - auto conn = reinterpret_cast(stream->data); - if (nread >= 0) { - conn->ReadData(std::string(buf->base, buf->base + nread)); - } else { - conn->TriggerShutdown(); + assert(stream == nullptr); + switch (uv_guess_handle(file_id)) { + case UV_TTY: { + auto tty = new uv_tty_t(); + uv_tty_init(this->Server->GetLoop(), tty, file_id, file_id == 0); + uv_tty_set_mode(tty, UV_TTY_MODE_NORMAL); + stream = reinterpret_cast(tty); + break; + } + case UV_FILE: + if (file_id == 0) { + return; + } + // Intentional fallthrough; stdin can _not_ be treated as a named + // pipe, however stdout can be. + CM_FALLTHROUGH; + case UV_NAMED_PIPE: { + auto pipe = new uv_pipe_t(); + uv_pipe_init(this->Server->GetLoop(), pipe, 0); + uv_pipe_open(pipe, file_id); + stream = reinterpret_cast(pipe); + break; + } + default: + assert(false && "Unable to determine stream type"); + return; } - - delete[](buf->base); + stream->data = static_cast(this); } -void on_write(uv_write_t* req, int status) +void cmStdIoConnection::SetServer(cmServerBase* s) { - (void)(status); - auto conn = reinterpret_cast(req->data); - - // Free req and buffer - write_req_t* wr = reinterpret_cast(req); - delete[](wr->buf.base); - delete wr; + cmConnection::SetServer(s); + if (!s) { + return; + } - conn->ProcessNextRequest(); + SetupStream(this->ReadStream, 0); + SetupStream(this->WriteStream, 1); } -void on_new_connection(uv_stream_t* stream, int status) +void shutdown_connection(uv_prepare_t* prepare) { - (void)(status); - auto conn = reinterpret_cast(stream->data); - conn->Connect(stream); -} + cmStdIoConnection* connection = + reinterpret_cast(prepare->data); -void on_signal(uv_signal_t* signal, int signum) -{ - auto conn = reinterpret_cast(signal->data); - (void)(signum); - conn->TriggerShutdown(); + if (!uv_is_closing(reinterpret_cast(prepare))) { + uv_close(reinterpret_cast(prepare), + &cmEventBasedConnection::on_close_delete); + } + connection->OnDisconnect(0); } -void on_signal_close(uv_handle_t* handle) +bool cmStdIoConnection::OnServeStart(std::string* pString) { - delete reinterpret_cast(handle); -} + Server->OnConnected(this); + if (this->ReadStream) { + 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_pipe_close(uv_handle_t* handle) -{ - delete reinterpret_cast(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); } -void on_tty_close(uv_handle_t* handle) +void cmStdIoConnection::ShutdownStream(uv_stream_t*& stream) { - delete reinterpret_cast(handle); -} + if (!stream) { + return; + } + switch (stream->type) { + case UV_TTY: { + assert(!uv_is_closing(reinterpret_cast(stream))); + if (!uv_is_closing(reinterpret_cast(stream))) { + uv_close(reinterpret_cast(stream), + &on_close_delete); + } + break; + } + case UV_FILE: + case UV_NAMED_PIPE: { + assert(!uv_is_closing(reinterpret_cast(stream))); + if (!uv_is_closing(reinterpret_cast(stream))) { + uv_close(reinterpret_cast(stream), + &on_close_delete); + } + break; + } + default: + assert(false && "Unable to determine stream type"); + } -} // namespace + stream = nullptr; +} -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) { + uv_read_stop(ReadStream); } - ~LoopGuard() - { - if (!this->Connection->mLoop) { - return; - } + ShutdownStream(ReadStream); + ShutdownStream(WriteStream); - 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() { - this->Server = s; } -bool cmServerConnection::ProcessEvents(std::string* errorMessage) +void cmConnectionBufferStrategy::clear() { - 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(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(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; } -void cmServerConnection::ReadData(const std::string& data) +std::string cmServerBufferStrategy::BufferOutMessage( + const std::string& rawBuffer) const { - this->RawReadBuffer += data; + return std::string("\n") + kSTART_MAGIC + std::string("\n") + rawBuffer + + kEND_MAGIC + std::string("\n"); +} +std::string cmServerBufferStrategy::BufferMessage(std::string& RawReadBuffer) +{ 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(needle) + 1); + RawReadBuffer.erase(RawReadBuffer.begin(), + RawReadBuffer.begin() + static_cast(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(this->SIGINTHandler), - &on_signal_close); // delete handle - uv_close(reinterpret_cast(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(ds)); - memcpy(req->buf.base, data.c_str(), ds); - - uv_write(reinterpret_cast(req), - static_cast(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(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(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(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(this->Output.pipe); - } - - SendGreetings(); - uv_read_start(this->ReadStream, on_alloc_buffer, on_read); - - return true; -} - -void cmServerStdIoConnection::TearDown() -{ - if (usesTty) { - uv_close(reinterpret_cast(this->Input.tty), &on_tty_close); - uv_close(reinterpret_cast(this->Output.tty), &on_tty_close); - this->Input.tty = nullptr; - this->Output.tty = nullptr; - } else { - uv_close(reinterpret_cast(this->Input.pipe), &on_pipe_close); - uv_close(reinterpret_cast(this->Output.pipe), - &on_pipe_close); - this->Input.pipe = nullptr; - this->Input.pipe = nullptr; + this->RequestBuffer += line; + this->RequestBuffer += "\n"; } - 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(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(this->ClientPipe), &on_pipe_close); - this->WriteStream->data = nullptr; - } - uv_close(reinterpret_cast(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(rejectPipe); - uv_accept(server, rejecter); - uv_close(reinterpret_cast(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(this->ClientPipe); - if (uv_accept(server, client) != 0) { - uv_close(reinterpret_cast(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..4ca908ddf 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 -class cmFileMonitor; -class cmServer; +#include "cmConnection.h" +#include "cmPipeConnection.h" +#include "cm_uv.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); + std::string BufferMessage(std::string& rawBuffer) override; + std::string BufferOutMessage(const std::string& rawBuffer) const override; - bool ProcessEvents(std::string* errorMessage); - - void ReadData(const std::string& data); - void TriggerShutdown(); - void WriteData(const std::string& data); - void ProcessNextRequest(); - - 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; + void SetupStream(uv_stream_t*& stream, int file_id); + void ShutdownStream(uv_stream_t*& stream); }; -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..405ff6b12 100644 --- a/Source/cmServerDictionary.h +++ b/Source/cmServerDictionary.h @@ -89,6 +89,11 @@ static const std::string kWARN_UNUSED_KEY = "warnUnused"; static const std::string kWATCHED_DIRECTORIES_KEY = "watchedDirectories"; static const std::string kWATCHED_FILES_KEY = "watchedFiles"; +static const std::string kTARGET_CROSS_REFERENCES_KEY = "crossReferences"; +static const std::string kLINE_NUMBER_KEY = "line"; +static const std::string kBACKTRACE_KEY = "backtrace"; +static const std::string kRELATED_STATEMENTS_KEY = "relatedStatements"; + static const std::string kSTART_MAGIC = "[== \"CMake Server\" ==["; static const std::string kEND_MAGIC = "]== \"CMake Server\" ==]"; diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index c5b7f6064..e835b7a2c 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -2,12 +2,14 @@ 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 "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmServer.h" @@ -18,6 +20,7 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmSystemTools.h" +#include "cmTarget.h" #include "cm_uv.h" #include "cmake.h" @@ -63,7 +66,7 @@ template Json::Value fromStringList(const T& in) { Json::Value result = Json::arrayValue; - for (const std::string& i : in) { + for (std::string const& i : in) { result.append(i); } return result; @@ -72,7 +75,7 @@ Json::Value fromStringList(const T& in) std::vector toStringList(const Json::Value& in) { std::vector result; - for (const auto& it : in) { + for (auto const& it : in) { result.push_back(it.asString()); } return result; @@ -86,19 +89,17 @@ void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir, { const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot() + '/'; std::vector const& makefiles = gg->GetMakefiles(); - for (auto it = makefiles.begin(); it != makefiles.end(); ++it) { - const std::vector listFiles = (*it)->GetListFiles(); + for (cmMakefile const* mf : makefiles) { + for (std::string const& lf : mf->GetListFiles()) { - for (auto jt = listFiles.begin(); jt != listFiles.end(); ++jt) { - - const std::string startOfFile = jt->substr(0, cmakeRootDir.size()); + const std::string startOfFile = lf.substr(0, cmakeRootDir.size()); const bool isInternal = (startOfFile == cmakeRootDir); - const bool isTemporary = !isInternal && (jt->find(buildDir + '/') == 0); + const bool isTemporary = !isInternal && (lf.find(buildDir + '/') == 0); - std::string toAdd = *jt; + std::string toAdd = lf; if (!sourceDir.empty()) { const std::string& relative = - cmSystemTools::RelativePath(sourceDir.c_str(), jt->c_str()); + cmSystemTools::RelativePath(sourceDir.c_str(), lf.c_str()); if (toAdd.size() > relative.size()) { toAdd = relative; } @@ -125,11 +126,13 @@ void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir, } // namespace -cmServerRequest::cmServerRequest(cmServer* server, const std::string& t, - const std::string& c, const Json::Value& d) +cmServerRequest::cmServerRequest(cmServer* server, cmConnection* connection, + const std::string& t, const std::string& c, + const Json::Value& d) : Type(t) , Cookie(c) , Data(d) + , Connection(connection) , m_Server(server) { } @@ -215,10 +218,10 @@ bool cmServerProtocol::Activate(cmServer* server, { assert(server); this->m_Server = server; - this->m_CMakeInstance = std::make_unique(cmake::RoleProject); + this->m_CMakeInstance = cm::make_unique(cmake::RoleProject); const bool result = this->DoActivate(request, errorMessage); if (!result) { - this->m_CMakeInstance = CM_NULLPTR; + this->m_CMakeInstance = nullptr; } return result; } @@ -247,9 +250,9 @@ bool cmServerProtocol::DoActivate(const cmServerRequest& /*request*/, return true; } -std::pair cmServerProtocol1_0::ProtocolVersion() const +std::pair cmServerProtocol1::ProtocolVersion() const { - return std::make_pair(1, 0); + return std::make_pair(1, 1); } static void setErrorMessage(std::string* errorMessage, const std::string& text) @@ -264,6 +267,10 @@ static bool testHomeDirectory(cmState* state, std::string& value, { 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,9 +281,6 @@ static bool testHomeDirectory(cmState* state, std::string& value, "source directory value.")); return false; } - if (value.empty()) { - value = cachedValue; - } return true; } @@ -287,20 +291,20 @@ static bool testValue(cmState* state, const std::string& key, const char* entry = state->GetCacheEntryValue(key); const std::string cachedValue = entry == nullptr ? std::string() : std::string(entry); - if (!cachedValue.empty() && !value.empty() && cachedValue != value) { + 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 = @@ -419,8 +423,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(status); @@ -443,7 +447,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); @@ -476,18 +480,14 @@ const cmServerResponse cmServerProtocol1_0::Process( 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 +499,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 +515,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 +530,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) { @@ -589,7 +589,7 @@ public: std::string Language; std::string Flags; std::vector Defines; - std::vector > IncludePathList; + std::vector> IncludePathList; }; bool LanguageData::operator==(const LanguageData& other) const @@ -602,11 +602,12 @@ bool LanguageData::operator==(const LanguageData& other) const void LanguageData::SetDefines(const std::set& defines) { std::vector result; - for (const auto& i : defines) { + result.reserve(defines.size()); + for (std::string const& i : defines) { result.push_back(i); } std::sort(result.begin(), result.end()); - Defines = result; + Defines = std::move(result); } namespace std { @@ -619,11 +620,11 @@ struct hash using std::hash; size_t result = hash()(in.Language) ^ hash()(in.Flags); - for (const auto& i : in.IncludePathList) { + for (auto const& i : in.IncludePathList) { result = result ^ (hash()(i.first) ^ (i.second ? std::numeric_limits::max() : 0)); } - for (const auto& i : in.Defines) { + for (auto const& i : in.Defines) { result = result ^ hash()(i); } result = @@ -647,7 +648,7 @@ static Json::Value DumpSourceFileGroup(const LanguageData& data, } if (!data.IncludePathList.empty()) { Json::Value includes = Json::arrayValue; - for (const auto& i : data.IncludePathList) { + for (auto const& i : data.IncludePathList) { Json::Value tmp = Json::objectValue; tmp[kPATH_KEY] = i.first; if (i.second) { @@ -665,7 +666,7 @@ static Json::Value DumpSourceFileGroup(const LanguageData& data, result[kIS_GENERATED_KEY] = data.IsGenerated; Json::Value sourcesValue = Json::arrayValue; - for (const auto& i : files) { + for (auto const& i : files) { const std::string relPath = cmSystemTools::RelativePath(baseDir.c_str(), i.c_str()); sourcesValue.append(relPath.size() < i.size() ? relPath : i); @@ -684,7 +685,7 @@ static Json::Value DumpSourceFilesList( std::vector files; target->GetSourceFiles(files, config); - std::unordered_map > fileGroups; + std::unordered_map> fileGroups; for (cmSourceFile* file : files) { LanguageData fileData; fileData.Language = file->GetLanguage(); @@ -721,8 +722,8 @@ static Json::Value DumpSourceFilesList( 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); + for (auto const& it : fileGroups) { + Json::Value group = DumpSourceFileGroup(it.first, it.second, baseDir); if (!group.isNull()) { result.append(group); } @@ -731,6 +732,37 @@ static Json::Value DumpSourceFilesList( return result; } +static Json::Value DumpBacktrace(const cmListFileBacktrace& backtrace) +{ + Json::Value result = Json::arrayValue; + + cmListFileBacktrace backtraceCopy = backtrace; + while (!backtraceCopy.Top().FilePath.empty()) { + Json::Value entry = Json::objectValue; + entry[kPATH_KEY] = backtraceCopy.Top().FilePath; + if (backtraceCopy.Top().Line) { + entry[kLINE_NUMBER_KEY] = static_cast(backtraceCopy.Top().Line); + } + if (!backtraceCopy.Top().Name.empty()) { + entry[kNAME_KEY] = backtraceCopy.Top().Name; + } + result.append(entry); + backtraceCopy = backtraceCopy.Pop(); + } + return result; +} + +static void DumpBacktraceRange(Json::Value& result, const std::string& type, + cmBacktraceRange range) +{ + for (auto const& bt : range) { + Json::Value obj = Json::objectValue; + obj[kTYPE_KEY] = type; + obj[kBACKTRACE_KEY] = DumpBacktrace(bt); + result.append(obj); + } +} + static Json::Value DumpTarget(cmGeneratorTarget* target, const std::string& config) { @@ -765,6 +797,22 @@ static Json::Value DumpTarget(cmGeneratorTarget* target, result[kFULL_NAME_KEY] = target->GetFullName(config); + Json::Value crossRefs = Json::objectValue; + crossRefs[kBACKTRACE_KEY] = DumpBacktrace(target->Target->GetBacktrace()); + + Json::Value statements = Json::arrayValue; + DumpBacktraceRange(statements, "target_compile_definitions", + target->Target->GetCompileDefinitionsBacktraces()); + DumpBacktraceRange(statements, "target_include_directories", + target->Target->GetIncludeDirectoriesBacktraces()); + DumpBacktraceRange(statements, "target_compile_options", + target->Target->GetCompileOptionsBacktraces()); + DumpBacktraceRange(statements, "target_link_libraries", + target->Target->GetLinkImplementationBacktraces()); + + crossRefs[kRELATED_STATEMENTS_KEY] = std::move(statements); + result[kTARGET_CROSS_REFERENCES_KEY] = std::move(crossRefs); + if (target->HaveWellDefinedOutputFiles()) { Json::Value artifacts = Json::arrayValue; artifacts.append( @@ -823,7 +871,7 @@ static Json::Value DumpTarget(cmGeneratorTarget* target, std::set languages; target->GetLanguages(languages, config); std::map languageDataMap; - for (const auto& lang : languages) { + for (std::string const& lang : languages) { LanguageData& ld = languageDataMap[lang]; ld.Language = lang; lg->GetTargetCompileFlags(target, config, lang, ld.Flags); @@ -832,7 +880,7 @@ static Json::Value DumpTarget(cmGeneratorTarget* target, ld.SetDefines(defines); std::vector includePathList; lg->GetIncludeDirectories(includePathList, target, lang, config, true); - for (auto i : includePathList) { + for (std::string const& i : includePathList) { ld.IncludePathList.push_back( std::make_pair(i, target->IsSystemIncludeDirectory(i, config))); } @@ -853,8 +901,8 @@ static Json::Value DumpTargetsList( Json::Value result = Json::arrayValue; std::vector targetList; - for (const auto& lgIt : generators) { - auto list = lgIt->GetGeneratorTargets(); + for (auto const& lgIt : generators) { + const auto& list = lgIt->GetGeneratorTargets(); targetList.insert(targetList.end(), list.begin(), list.end()); } std::sort(targetList.begin(), targetList.end()); @@ -875,7 +923,7 @@ static Json::Value DumpProjectList(const cmake* cm, std::string const& config) auto globalGen = cm->GetGlobalGenerator(); - for (const auto& projectIt : globalGen->GetProjectMap()) { + for (auto const& projectIt : globalGen->GetProjectMap()) { Json::Value pObj = Json::objectValue; pObj[kNAME_KEY] = projectIt.first; @@ -910,14 +958,14 @@ static Json::Value DumpConfigurationsList(const cmake* cm) { Json::Value result = Json::arrayValue; - for (const std::string& c : getConfigurations(cm)) { + for (std::string const& 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) { @@ -929,7 +977,7 @@ cmServerResponse cmServerProtocol1_0::ProcessCodeModel( return request.Reply(result); } -cmServerResponse cmServerProtocol1_0::ProcessCompute( +cmServerResponse cmServerProtocol1::ProcessCompute( const cmServerRequest& request) { if (this->m_State > STATE_CONFIGURED) { @@ -949,7 +997,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 +1021,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; @@ -1055,7 +1103,7 @@ cmServerResponse cmServerProtocol1_0::ProcessConfigure( return request.Reply(Json::Value()); } -cmServerResponse cmServerProtocol1_0::ProcessGlobalSettings( +cmServerResponse cmServerProtocol1::ProcessGlobalSettings( const cmServerRequest& request) { cmake* cm = this->CMakeInstance(); @@ -1091,7 +1139,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 boolValues = { @@ -1099,7 +1147,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 +1171,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,7 +1190,7 @@ cmServerResponse cmServerProtocol1_0::ProcessFileSystemWatchers( return request.Reply(result); } -cmServerProtocol1_0::GeneratorInformation::GeneratorInformation( +cmServerProtocol1::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) @@ -1155,7 +1203,7 @@ cmServerProtocol1_0::GeneratorInformation::GeneratorInformation( { } -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..124ac7f67 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 #include +class cmConnection; class cmFileMonitor; class cmServer; class cmServerRequest; @@ -52,9 +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, + cmServerRequest(cmServer* server, cmConnection* connection, + const std::string& t, const std::string& c, const Json::Value& d); void ReportProgress(int min, int current, int max, @@ -98,7 +101,7 @@ private: friend class cmServer; }; -class cmServerProtocol1_0 : public cmServerProtocol +class cmServerProtocol1 : public cmServerProtocol { public: std::pair ProtocolVersion() const override; diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx index 820e7f695..b32cda3cd 100644 --- a/Source/cmSetCommand.cxx +++ b/Source/cmSetCommand.cxx @@ -61,7 +61,7 @@ bool cmSetCommand::InitialPass(std::vector 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); + this->Makefile->RaiseScope(variable, nullptr); return true; } @@ -75,8 +75,8 @@ bool cmSetCommand::InitialPass(std::vector 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 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 #include @@ -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 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 #include @@ -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 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..7efcc0403 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -141,7 +141,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); @@ -191,7 +191,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 +204,19 @@ bool cmSetPropertyCommand::HandleDirectoryMode() bool cmSetPropertyCommand::HandleTargetMode() { - for (std::set::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 +231,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 +247,15 @@ bool cmSetPropertyCommand::HandleTarget(cmTarget* target) bool cmSetPropertyCommand::HandleSourceMode() { - for (std::set::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 +269,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 +301,8 @@ bool cmSetPropertyCommand::HandleTestMode() if (!this->Names.empty()) { std::ostringstream e; e << "given TEST names that do not exist:\n"; - for (std::set::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 +316,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); @@ -359,19 +356,18 @@ bool cmSetPropertyCommand::HandleCacheMode() return false; } - for (std::set::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 +399,15 @@ bool cmSetPropertyCommand::HandleInstallMode() { cmake* cm = this->Makefile->GetCMakeInstance(); - for (std::set::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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: std::set Names; 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; static bool RunCommand(cmMakefile* mf, std::vector::const_iterator filebeg, 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; /** * Used by this command and cmSetPropertiesCommand 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; static bool SetOneTest(const std::string& tname, std::vector& propertyPairs, diff --git a/Source/cmSiteNameCommand.cxx b/Source/cmSiteNameCommand.cxx index 7eace268f..d2e83a6aa 100644 --- a/Source/cmSiteNameCommand.cxx +++ b/Source/cmSiteNameCommand.cxx @@ -52,8 +52,8 @@ bool cmSiteNameCommand::InitialPass(std::vector const& args, // try to find the hostname for this computer if (!cmSystemTools::IsOff(hostname_cmd.c_str())) { std::string host; - cmSystemTools::RunSingleCommand(hostname_cmd.c_str(), &host, CM_NULLPTR, - CM_NULLPTR, CM_NULLPTR, + cmSystemTools::RunSingleCommand(hostname_cmd.c_str(), &host, nullptr, + nullptr, nullptr, cmSystemTools::OUTPUT_NONE); // got the hostname 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 5c4f18b40..0964bea6b 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -15,15 +15,13 @@ cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name) : Location(mf, name) { - this->CustomCommand = CM_NULLPTR; + this->CustomCommand = 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 @@ -131,17 +129,17 @@ bool cmSourceFile::FindFullPath(std::string* error) // 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 }; + const char* tryDirs[3] = { nullptr, nullptr, nullptr }; if (this->Location.DirectoryIsAmbiguous()) { tryDirs[0] = mf->GetCurrentSourceDirectory(); tryDirs[1] = mf->GetCurrentBinaryDirectory(); } else { tryDirs[0] = ""; } - const std::vector& srcExts = - mf->GetCMakeInstance()->GetSourceExtensions(); - std::vector hdrExts = - mf->GetCMakeInstance()->GetHeaderExtensions(); + + cmake const* const cmakeInst = mf->GetCMakeInstance(); + std::vector const& srcExts = cmakeInst->GetSourceExtensions(); + std::vector const& hdrExts = cmakeInst->GetHeaderExtensions(); for (const char* const* di = tryDirs; *di; ++di) { std::string tryPath = this->Location.GetDirectory(); if (!tryPath.empty()) { @@ -152,15 +150,13 @@ bool cmSourceFile::FindFullPath(std::string* error) if (this->TryFullPath(tryPath, "")) { return true; } - for (std::vector::const_iterator ei = srcExts.begin(); - ei != srcExts.end(); ++ei) { - if (this->TryFullPath(tryPath, *ei)) { + for (std::string const& ext : srcExts) { + if (this->TryFullPath(tryPath, ext)) { return true; } } - for (std::vector::const_iterator ei = hdrExts.begin(); - ei != hdrExts.end(); ++ei) { - if (this->TryFullPath(tryPath, *ei)) { + for (std::string const& ext : hdrExts) { + if (this->TryFullPath(tryPath, ext)) { return true; } } @@ -173,13 +169,11 @@ bool cmSourceFile::FindFullPath(std::string* error) } missing += this->Location.GetName(); e << "Cannot find source file:\n " << missing << "\nTried extensions"; - for (std::vector::const_iterator ext = srcExts.begin(); - ext != srcExts.end(); ++ext) { - e << " ." << *ext; + for (std::string const& srcExt : srcExts) { + e << " ." << srcExt; } - for (std::vector::const_iterator ext = hdrExts.begin(); - ext != hdrExts.end(); ++ext) { - e << " ." << *ext; + for (std::string const& ext : hdrExts) { + e << " ." << ext; } if (error) { *error = e.str(); @@ -245,13 +239,6 @@ bool cmSourceFile::Matches(cmSourceFileLocation const& loc) 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(mf)->AddQtUiFileWithOptions(this); - } - } } void cmSourceFile::AppendProperty(const std::string& prop, const char* value, @@ -290,7 +277,7 @@ const char* cmSourceFile::GetProperty(const std::string& prop) const // Check for computed properties. if (prop == "LOCATION") { if (this->FullPath.empty()) { - return CM_NULLPTR; + return nullptr; } return this->FullPath.c_str(); } diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 0be659c5f..c2105d224 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -3,7 +3,7 @@ #ifndef cmSourceFile_h #define cmSourceFile_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmPropertyMap.h" #include "cmSourceFileLocation.h" @@ -57,7 +57,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; /** @@ -107,7 +107,6 @@ private: std::string ObjectLibrary; std::vector Depends; bool FindFullPathFailed; - bool IsUiFile; bool FindFullPath(std::string* error); bool TryFullPath(const std::string& path, const std::string& ext); @@ -120,4 +119,10 @@ private: // 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|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..4f337f246 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -2,8 +2,6 @@ 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" @@ -15,7 +13,7 @@ #include cmSourceFileLocation::cmSourceFileLocation() - : Makefile(CM_NULLPTR) + : Makefile(nullptr) , AmbiguousDirectory(true) , AmbiguousExtension(true) { @@ -30,21 +28,6 @@ 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) : Makefile(mf) diff --git a/Source/cmSourceFileLocation.h b/Source/cmSourceFileLocation.h index 6dbc2daed..467682db9 100644 --- a/Source/cmSourceFileLocation.h +++ b/Source/cmSourceFileLocation.h @@ -29,7 +29,6 @@ public: cmSourceFileLocation(cmMakefile const* mf, const std::string& name); cmSourceFileLocation(); cmSourceFileLocation(const cmSourceFileLocation& loc); - cmSourceFileLocation& operator=(const cmSourceFileLocation& loc); /** * Return whether the given source file location could refers to the @@ -79,7 +78,7 @@ public: */ cmMakefile const* GetMakefile() const { return this->Makefile; } private: - cmMakefile const* Makefile; + cmMakefile const* const Makefile; bool AmbiguousDirectory; bool AmbiguousExtension; std::string Directory; @@ -90,6 +89,8 @@ private: // Update the location with additional knowledge. void Update(cmSourceFileLocation const& loc); void UpdateExtension(const std::string& name); + + cmSourceFileLocation& operator=(const cmSourceFileLocation& loc) = delete; }; #endif diff --git a/Source/cmSourceGroup.cxx b/Source/cmSourceGroup.cxx index 104e959a9..fba4c31d3 100644 --- a/Source/cmSourceGroup.cxx +++ b/Source/cmSourceGroup.cxx @@ -114,7 +114,7 @@ cmSourceGroup* cmSourceGroup::LookupChild(const char* name) const } // if no child with this name was found return NULL - return CM_NULLPTR; + return nullptr; } cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const char* name) @@ -134,7 +134,7 @@ cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const char* name) return result; } } - return CM_NULLPTR; + return nullptr; } cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const char* name) @@ -155,7 +155,7 @@ cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const char* name) return this; } - return CM_NULLPTR; + return nullptr; } std::vector const& cmSourceGroup::GetGroupChildren() const diff --git a/Source/cmSourceGroup.h b/Source/cmSourceGroup.h index 97affed6e..e8bd69767 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 @@ -27,7 +27,7 @@ class cmSourceGroup { public: cmSourceGroup(const char* name, const char* regex, - const char* parentName = CM_NULLPTR); + const char* parentName = nullptr); cmSourceGroup(cmSourceGroup const& r); ~cmSourceGroup(); cmSourceGroup& operator=(cmSourceGroup const&); diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx index a966300c0..69983a875 100644 --- a/Source/cmSourceGroupCommand.cxx +++ b/Source/cmSourceGroupCommand.cxx @@ -41,8 +41,8 @@ std::set getSourceGroupFilesPaths( std::set 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 +51,9 @@ std::set getSourceGroupFilesPaths( bool rootIsPrefix(const std::string& root, const std::vector& 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,23 +61,6 @@ bool rootIsPrefix(const std::string& root, return true; } -cmSourceGroup* addSourceGroup(const std::vector& 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) { @@ -108,26 +91,25 @@ bool addFilesToItsSourceGroups(const std::string& root, { cmSourceGroup* sg; - for (std::set::const_iterator it = sgFilesPaths.begin(); - it != sgFilesPaths.end(); ++it) { + for (std::string const& sgFilesPath : sgFilesPaths) { std::vector tokenizedPath; if (!prefix.empty()) { - tokenizedPath = tokenizePath(prefix + '/' + *it); + tokenizedPath = tokenizePath(prefix + '/' + sgFilesPath); } else { - tokenizedPath = tokenizePath(*it); + tokenizedPath = tokenizePath(sgFilesPath); } if (tokenizedPath.size() > 1) { tokenizedPath.pop_back(); - sg = addSourceGroup(tokenizedPath, makefile); + 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); } } @@ -158,20 +140,7 @@ bool cmSourceGroupCommand::InitialPass(std::vector const& args, return true; } - std::string delimiter = "\\"; - if (this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER")) { - delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"); - } - - std::vector folders = - cmSystemTools::tokenize(args[0], delimiter); - - cmSourceGroup* sg = CM_NULLPTR; - sg = this->Makefile->GetSourceGroup(folders); - if (!sg) { - this->Makefile->AddSourceGroup(folders); - sg = this->Makefile->GetSourceGroup(folders); - } + cmSourceGroup* sg = this->Makefile->GetOrCreateSourceGroup(args[0]); if (!sg) { this->SetError("Could not create or find source group"); diff --git a/Source/cmSourceGroupCommand.h b/Source/cmSourceGroupCommand.h index 7d56b0d65..ed02ca59a 100644 --- a/Source/cmSourceGroupCommand.h +++ b/Source/cmSourceGroupCommand.h @@ -3,7 +3,7 @@ #ifndef cmSourceGroupCommand_h #define cmSourceGroupCommand_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -24,14 +24,14 @@ 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: bool processTree(const std::vector& args, diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 92e47f748..5957b5bb2 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -63,12 +63,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) { @@ -132,7 +132,7 @@ 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(); } @@ -188,7 +188,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); } @@ -224,7 +224,7 @@ 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() @@ -303,7 +303,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, @@ -436,7 +436,7 @@ cmCommand* cmState::GetCommand(std::string const& name) const if (pos != this->BuiltinCommands.end()) { return pos->second; } - return CM_NULLPTR; + return nullptr; } std::vector cmState::GetCommandNames() const @@ -444,15 +444,11 @@ std::vector cmState::GetCommandNames() const std::vector commandNames; commandNames.reserve(this->BuiltinCommands.size() + this->ScriptedCommands.size()); - for (std::map::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::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()), diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 46a185848..85e6366d9 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "cmProperty.h" @@ -81,7 +80,7 @@ void cmStateDirectory::ComputeRelativePathTopBinary() if (result.size() < 2 || result.substr(0, 2) != "//") { this->DirectoryState->RelativePathTopBinary = result; } else { - this->DirectoryState->RelativePathTopBinary = ""; + this->DirectoryState->RelativePathTopBinary.clear(); } } @@ -423,7 +422,7 @@ 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()) { @@ -443,9 +442,9 @@ const char* cmStateDirectory::GetProperty(const std::string& prop, std::vector child_dirs; std::vector const& children = this->DirectoryState->Children; - for (std::vector::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(); @@ -514,10 +513,8 @@ std::vector cmStateDirectory::GetPropertyKeys() const { std::vector 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/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 77413c7b5..bdef3e529 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -220,7 +220,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 cmStateSnapshot::UnusedKeys() const diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h index 6293803b9..94d6274b9 100644 --- a/Source/cmStateSnapshot.h +++ b/Source/cmStateSnapshot.h @@ -19,7 +19,7 @@ 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; diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 7a097ba21..55af0785d 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -4,6 +4,7 @@ #include "cmsys/RegularExpression.hxx" #include +#include // IWYU pragma: keep #include #include #include @@ -15,7 +16,6 @@ #include "cmSystemTools.h" #include "cmTimestamp.h" #include "cmUuid.h" -#include "cm_auto_ptr.hxx" class cmExecutionStatus; @@ -62,6 +62,9 @@ bool cmStringCommand::InitialPass(std::vector const& args, if (subCommand == "APPEND") { return this->HandleAppendCommand(args); } + if (subCommand == "PREPEND") { + return this->HandlePrependCommand(args); + } if (subCommand == "CONCAT") { return this->HandleConcatCommand(args); } @@ -105,8 +108,8 @@ bool cmStringCommand::HandleHashCommand(std::vector const& args) return false; } - CM_AUTO_PTR hash(cmCryptoHash::New(args[0].c_str())); - if (hash.get()) { + std::unique_ptr 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; @@ -309,6 +312,7 @@ bool cmStringCommand::RegexMatchAll(std::vector 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(); @@ -391,6 +395,7 @@ bool cmStringCommand::RegexReplace(std::vector const& args) std::string output; std::string::size_type base = 0; while (re.find(input.c_str() + base)) { + this->Makefile->ClearMatches(); this->Makefile->StoreMatches(re); std::string::size_type l2 = re.start(); std::string::size_type r = re.end(); @@ -407,13 +412,13 @@ bool cmStringCommand::RegexReplace(std::vector const& args) } // Concatenate the replacement for the match. - for (unsigned int i = 0; i < replacement.size(); ++i) { - if (replacement[i].number < 0) { + for (RegexReplacement const& i : replacement) { + if (i.number < 0) { // This is just a plain-text part of the replacement. - output += replacement[i].value; + output += i.value; } else { // Replace with part of the match. - int n = replacement[i].number; + int n = 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; @@ -641,6 +646,30 @@ bool cmStringCommand::HandleAppendCommand(std::vector const& args) return true; } +bool cmStringCommand::HandlePrependCommand( + std::vector 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 const& args) { if (args.size() < 2) { @@ -789,7 +818,7 @@ bool cmStringCommand::HandleRandomCommand(std::vector 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)); + int idx = static_cast(sizeofAlphabet * rand() / (RAND_MAX + 1.0)); result.push_back(*(alphaPtr + idx)); } result.push_back(0); diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index 88015ad5e..b287e37b7 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -3,7 +3,7 @@ #ifndef cmStringCommand_h #define cmStringCommand_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -22,14 +22,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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; protected: bool HandleConfigureCommand(std::vector const& args); @@ -46,6 +46,7 @@ protected: bool HandleLengthCommand(std::vector const& args); bool HandleSubstringCommand(std::vector const& args); bool HandleAppendCommand(std::vector const& args); + bool HandlePrependCommand(std::vector const& args); bool HandleConcatCommand(std::vector const& args); bool HandleStripCommand(std::vector const& args); bool HandleRandomCommand(std::vector const& args); diff --git a/Source/cmSubdirCommand.cxx b/Source/cmSubdirCommand.cxx index 3727dfa25..c74ca59bb 100644 --- a/Source/cmSubdirCommand.cxx +++ b/Source/cmSubdirCommand.cxx @@ -18,36 +18,35 @@ bool cmSubdirCommand::InitialPass(std::vector const& args, bool res = true; bool excludeFromAll = false; - for (std::vector::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; + std::string(this->Makefile->GetCurrentSourceDirectory()) + "/" + i; if (cmSystemTools::FileIsDirectory(srcPath)) { std::string binPath = - std::string(this->Makefile->GetCurrentBinaryDirectory()) + "/" + *i; + std::string(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); + 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 #include @@ -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 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index f7192e0b6..63c1452e6 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -353,8 +353,8 @@ bool cmSystemTools::IsInternallyOn(const char* val) return false; } - for (std::string::iterator c = v.begin(); c != v.end(); c++) { - *c = static_cast(toupper(*c)); + for (char& c : v) { + c = static_cast(toupper(c)); } return v == "I_ON"; } @@ -378,8 +378,8 @@ bool cmSystemTools::IsOn(const char* val) onValues.insert("TRUE"); onValues.insert("Y"); } - for (std::string::iterator c = v.begin(); c != v.end(); c++) { - *c = static_cast(toupper(*c)); + for (char& c : v) { + c = static_cast(toupper(c)); } return (onValues.count(v) > 0); } @@ -414,8 +414,8 @@ bool cmSystemTools::IsOff(const char* val) } // Try and avoid toupper(). std::string v(val, len); - for (std::string::iterator c = v.begin(); c != v.end(); c++) { - *c = static_cast(toupper(*c)); + for (char& c : v) { + c = static_cast(toupper(c)); } return (offValues.count(v) > 0); } @@ -458,7 +458,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 { @@ -559,7 +559,7 @@ std::vector cmSystemTools::ParseArguments(const char* command) while (*c == ' ' || *c == '\t') { ++c; } - arg = ""; + arg.clear(); if (*c == '"') { // Parse a quoted argument. ++c; @@ -603,6 +603,56 @@ std::vector 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(*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(*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 = @@ -650,11 +700,11 @@ bool cmSystemTools::RunSingleCommand(std::vector const& command, double timeout, Encoding encoding) { std::vector argv; - for (std::vector::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()); @@ -666,12 +716,12 @@ bool cmSystemTools::RunSingleCommand(std::vector 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); @@ -687,7 +737,7 @@ bool cmSystemTools::RunSingleCommand(std::vector 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) { @@ -727,7 +777,7 @@ bool cmSystemTools::RunSingleCommand(std::vector const& command, } } - cmsysProcess_WaitForExit(cp, CM_NULLPTR); + cmsysProcess_WaitForExit(cp, nullptr); if (captureStdOut) { captureStdOut->assign(tempStdOut.begin(), tempStdOut.end()); @@ -754,6 +804,8 @@ bool cmSystemTools::RunSingleCommand(std::vector 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 +815,8 @@ bool cmSystemTools::RunSingleCommand(std::vector 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) { @@ -814,11 +868,10 @@ bool cmSystemTools::DoesFileExistWithExtensions( { std::string hname; - for (std::vector::const_iterator ext = headerExts.begin(); - ext != headerExts.end(); ++ext) { + for (std::string const& headerExt : headerExts) { hname = name; hname += "."; - hname += *ext; + hname += headerExt; if (cmSystemTools::FileExists(hname.c_str())) { return true; } @@ -934,19 +987,17 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname) #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 } @@ -1138,7 +1189,7 @@ void cmSystemTools::ExpandListArgument(const std::string& arg, if (!newArg.empty() || emptyArgs) { // Add the last argument if the string is not empty. newargs.push_back(newArg); - newArg = ""; + newArg.clear(); } } } break; @@ -1329,7 +1380,7 @@ std::string cmSystemTools::CollapseCombinedPath(std::string const& dir, if (fileComponents.empty()) { return dir; } - if (fileComponents[0] != "") { + if (!fileComponents[0].empty()) { // File is not a relative path. return file; } @@ -1369,9 +1420,8 @@ std::vector cmSystemTools::GetEnvironmentVariables() void cmSystemTools::AppendEnv(std::vector const& env) { - for (std::vector::const_iterator eit = env.begin(); - eit != env.end(); ++eit) { - cmSystemTools::PutEnv(*eit); + for (std::string const& eit : env) { + cmSystemTools::PutEnv(eit); } } @@ -1384,10 +1434,7 @@ cmSystemTools::SaveRestoreEnvironment::~SaveRestoreEnvironment() { // First clear everything in the current environment: std::vector currentEnv = GetEnvironmentVariables(); - for (std::vector::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); @@ -1466,9 +1513,7 @@ bool cmSystemTools::CreateTar(const char* outFileName, a.SetMTime(mtime); a.SetVerbose(verbose); - for (std::vector::const_iterator i = files.begin(); - i != files.end(); ++i) { - std::string path = *i; + for (auto path : files) { if (cmSystemTools::FileIsFullPath(path.c_str())) { // Get the relative path to the file. path = cmSystemTools::RelativePath(cwd.c_str(), path.c_str()); @@ -1520,22 +1565,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(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(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(archive_entry_gid(entry))); w = strlen(tmp); fprintf(out, "%s", tmp); } @@ -1547,8 +1592,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,12 +1602,12 @@ 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(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(gs_width - w), tmp); /* Format the time using 'ls -l' conventions. */ tim = archive_entry_mtime(entry); @@ -1730,7 +1776,7 @@ int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line, double timeout, std::vector& out, std::vector& err) { - line = ""; + line.clear(); std::vector::iterator outiter = out.begin(); std::vector::iterator erriter = err.begin(); cmProcessOutput processOutput; @@ -1973,7 +2019,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 +2028,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(getpid()); unsigned int tv_sec = static_cast(t.tv_sec); unsigned int tv_usec = static_cast(t.tv_usec); @@ -2020,7 +2066,7 @@ void cmSystemTools::FindCMakeResources(const char* argv0) #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(malloc(exe_path_size)); _NSGetExecutablePath(exe_path, &exe_path_size); } exe_dir = @@ -2070,19 +2116,19 @@ void cmSystemTools::FindCMakeResources(const char* argv0) cmSystemToolsCMakeGUICommand += "/cmake-gui"; cmSystemToolsCMakeGUICommand += cmSystemTools::GetExecutableExtension(); if (!cmSystemTools::FileExists(cmSystemToolsCMakeGUICommand.c_str())) { - cmSystemToolsCMakeGUICommand = ""; + cmSystemToolsCMakeGUICommand.clear(); } cmSystemToolsCMakeCursesCommand = exe_dir; cmSystemToolsCMakeCursesCommand += "/ccmake"; cmSystemToolsCMakeCursesCommand += cmSystemTools::GetExecutableExtension(); if (!cmSystemTools::FileExists(cmSystemToolsCMakeCursesCommand.c_str())) { - cmSystemToolsCMakeCursesCommand = ""; + cmSystemToolsCMakeCursesCommand.clear(); } cmSystemToolsCMClDepsCommand = exe_dir; cmSystemToolsCMClDepsCommand += "/cmcldeps"; cmSystemToolsCMClDepsCommand += cmSystemTools::GetExecutableExtension(); if (!cmSystemTools::FileExists(cmSystemToolsCMClDepsCommand.c_str())) { - cmSystemToolsCMClDepsCommand = ""; + cmSystemToolsCMClDepsCommand.clear(); } #ifdef CMAKE_BUILD_WITH_CMAKE @@ -2280,12 +2326,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 +2344,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 +2497,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 +2640,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 +2659,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; } @@ -2734,13 +2781,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) diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 9de796728..e7082e6b1 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -3,8 +3,9 @@ #ifndef cmSystemTools_h #define cmSystemTools_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep +#include "cmCryptoHash.h" #include "cmProcessOutput.h" #include "cmsys/Process.h" #include "cmsys/SystemTools.hxx" // IWYU pragma: export @@ -61,34 +62,34 @@ public: * set to false, will disable furthur messages (cancel). */ static void SetMessageCallback(MessageCallback f, - void* clientData = CM_NULLPTR); + void* clientData = nullptr); /** * 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 char* m, const char* m2 = nullptr, + const char* m3 = nullptr, const char* m4 = nullptr); /** * Display a message. */ - static void Message(const char* m, const char* title = CM_NULLPTR); + static void Message(const char* m, const char* title = nullptr); typedef void (*OutputCallback)(const char*, size_t length, void*); ///! Send a string to stdout static void Stdout(const char* s); static void Stdout(const char* s, size_t length); - static void SetStdoutCallback(OutputCallback, void* clientData = CM_NULLPTR); + static void SetStdoutCallback(OutputCallback, void* clientData = nullptr); ///! 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); + static void SetStderrCallback(OutputCallback, void* clientData = nullptr); typedef bool (*InterruptCallback)(void*); static void SetInterruptCallback(InterruptCallback f, - void* clientData = CM_NULLPTR); + void* clientData = nullptr); static bool GetInterruptFlag(); ///! Return true if there was an error at any point. @@ -179,8 +180,9 @@ public: if possible). */ static bool RenameFile(const char* oldname, const char* newname); - ///! Compute the md5sum of a file - static bool ComputeFileMD5(const std::string& source, char* md5out); + ///! Compute the 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); @@ -218,10 +220,10 @@ public: 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, + std::string* captureStdOut = nullptr, + std::string* captureStdErr = nullptr, + int* retVal = nullptr, + const char* dir = nullptr, OutputOption outputflag = OUTPUT_MERGE, double timeout = 0.0); /** @@ -230,10 +232,10 @@ public: * be in comand[1]...command[command.size()] */ static bool RunSingleCommand(std::vector 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, Encoding encoding = cmProcessOutput::Auto); @@ -253,6 +255,11 @@ public: static void ParseUnixCommandLine(const char* command, std::vector& 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 * **/ @@ -461,13 +468,12 @@ 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. */ diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index c95a3ca2c..c6cd5026f 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -5,10 +5,12 @@ #include "cmsys/RegularExpression.hxx" #include #include +#include #include #include #include #include +#include #include "cmAlgorithms.h" #include "cmGeneratorExpression.h" @@ -26,7 +28,6 @@ #include "cmStateSnapshot.h" #include "cmSystemTools.h" #include "cmTargetPropertyComputer.h" -#include "cm_unordered_set.hxx" #include "cmake.h" template <> @@ -75,27 +76,23 @@ const char* cmTargetPropertyComputer::GetSources( { cmStringRange entries = tgt->GetSourceEntries(); if (entries.empty()) { - return CM_NULLPTR; + return nullptr; } std::ostringstream ss; const char* sep = ""; - for (std::vector::const_iterator i = entries.begin(); - i != entries.end(); ++i) { - std::string const& entry = *i; - + for (std::string const& entry : entries) { std::vector files; cmSystemTools::ExpandListArgument(entry, files); - for (std::vector::const_iterator li = files.begin(); - li != files.end(); ++li) { - if (cmHasLiteralPrefix(*li, "$size() - 1] == '>') { - std::string objLibName = li->substr(17, li->size() - 18); + for (std::string const& file : files) { + if (cmHasLiteralPrefix(file, "$') { + std::string objLibName = file.substr(17, file.size() - 18); if (cmGeneratorExpression::Find(objLibName) != std::string::npos) { ss << sep; sep = ";"; - ss << *li; + ss << file; continue; } @@ -130,14 +127,14 @@ const char* cmTargetPropertyComputer::GetSources( 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(); @@ -211,77 +208,79 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, // 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("ANDROID_API", nullptr); + this->SetPropertyDefault("ANDROID_API_MIN", nullptr); + this->SetPropertyDefault("ANDROID_ARCH", nullptr); + this->SetPropertyDefault("ANDROID_STL_TYPE", nullptr); + this->SetPropertyDefault("ANDROID_SKIP_ANT_STEP", nullptr); + this->SetPropertyDefault("ANDROID_PROCESS_MAX", nullptr); + this->SetPropertyDefault("ANDROID_PROGUARD", nullptr); + this->SetPropertyDefault("ANDROID_PROGUARD_CONFIG_PATH", nullptr); + this->SetPropertyDefault("ANDROID_SECURE_PROPS_PATH", nullptr); + this->SetPropertyDefault("ANDROID_NATIVE_LIB_DIRECTORIES", nullptr); + this->SetPropertyDefault("ANDROID_NATIVE_LIB_DEPENDENCIES", nullptr); + this->SetPropertyDefault("ANDROID_JAVA_SOURCE_DIR", nullptr); + this->SetPropertyDefault("ANDROID_JAR_DIRECTORIES", nullptr); + this->SetPropertyDefault("ANDROID_JAR_DEPENDENCIES", nullptr); + this->SetPropertyDefault("ANDROID_ASSETS_DIRECTORIES", nullptr); + this->SetPropertyDefault("ANDROID_ANT_ADDITIONAL_OPTIONS", nullptr); + this->SetPropertyDefault("BUILD_RPATH", nullptr); + this->SetPropertyDefault("INSTALL_NAME_DIR", nullptr); this->SetPropertyDefault("INSTALL_RPATH", ""); this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF"); - this->SetPropertyDefault("INTERPROCEDURAL_OPTIMIZATION", CM_NULLPTR); + this->SetPropertyDefault("INTERPROCEDURAL_OPTIMIZATION", 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); - } - - if (this->GetType() != cmStateEnums::UTILITY) { - this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", CM_NULLPTR); + this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", nullptr); + this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", nullptr); + this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", nullptr); + this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", nullptr); + this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", nullptr); + this->SetPropertyDefault("Fortran_FORMAT", nullptr); + this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", nullptr); + this->SetPropertyDefault("GNUtoMS", nullptr); + this->SetPropertyDefault("OSX_ARCHITECTURES", nullptr); + this->SetPropertyDefault("IOS_INSTALL_COMBINED", nullptr); + this->SetPropertyDefault("AUTOMOC", nullptr); + this->SetPropertyDefault("AUTOUIC", nullptr); + this->SetPropertyDefault("AUTORCC", nullptr); + this->SetPropertyDefault("AUTOMOC_COMPILER_PREDEFINES", nullptr); + this->SetPropertyDefault("AUTOMOC_DEPEND_FILTERS", nullptr); + this->SetPropertyDefault("AUTOMOC_MACRO_NAMES", nullptr); + this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", nullptr); + this->SetPropertyDefault("AUTOUIC_OPTIONS", nullptr); + this->SetPropertyDefault("AUTOUIC_SEARCH_PATHS", nullptr); + this->SetPropertyDefault("AUTORCC_OPTIONS", nullptr); + this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", nullptr); + this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", nullptr); + this->SetPropertyDefault("WIN32_EXECUTABLE", nullptr); + this->SetPropertyDefault("MACOSX_BUNDLE", nullptr); + this->SetPropertyDefault("MACOSX_RPATH", nullptr); + this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", nullptr); + this->SetPropertyDefault("BUILD_WITH_INSTALL_NAME_DIR", nullptr); + this->SetPropertyDefault("C_CLANG_TIDY", nullptr); + this->SetPropertyDefault("C_COMPILER_LAUNCHER", nullptr); + this->SetPropertyDefault("C_CPPLINT", nullptr); + this->SetPropertyDefault("C_CPPCHECK", nullptr); + this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", nullptr); + this->SetPropertyDefault("LINK_WHAT_YOU_USE", nullptr); + this->SetPropertyDefault("C_STANDARD", nullptr); + this->SetPropertyDefault("C_STANDARD_REQUIRED", nullptr); + this->SetPropertyDefault("C_EXTENSIONS", nullptr); + this->SetPropertyDefault("CXX_CLANG_TIDY", nullptr); + this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", nullptr); + this->SetPropertyDefault("CXX_CPPLINT", nullptr); + this->SetPropertyDefault("CXX_CPPCHECK", nullptr); + this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", nullptr); + this->SetPropertyDefault("CXX_STANDARD", nullptr); + this->SetPropertyDefault("CXX_STANDARD_REQUIRED", nullptr); + this->SetPropertyDefault("CXX_EXTENSIONS", nullptr); + this->SetPropertyDefault("CUDA_STANDARD", nullptr); + this->SetPropertyDefault("CUDA_STANDARD_REQUIRED", nullptr); + this->SetPropertyDefault("CUDA_EXTENSIONS", nullptr); + this->SetPropertyDefault("CUDA_COMPILER_LAUNCHER", nullptr); + this->SetPropertyDefault("LINK_SEARCH_START_STATIC", nullptr); + this->SetPropertyDefault("LINK_SEARCH_END_STATIC", nullptr); } // Collect the set of configuration types. @@ -295,11 +294,10 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, "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_", nullptr }; - for (std::vector::iterator ci = configNames.begin(); - ci != configNames.end(); ++ci) { - std::string configUpper = cmSystemTools::UpperCase(*ci); + for (std::string const& configName : configNames) { + std::string configUpper = cmSystemTools::UpperCase(configName); for (const char** p = configProps; *p; ++p) { // Interface libraries have no output locations, so honor only // the configuration map. @@ -309,7 +307,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, } std::string property = *p; property += configUpper; - this->SetPropertyDefault(property, CM_NULLPTR); + this->SetPropertyDefault(property, nullptr); } // Initialize per-configuration name postfix property from the @@ -319,9 +317,9 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, // property directly. if (this->TargetTypeValue != cmStateEnums::EXECUTABLE && this->TargetTypeValue != cmStateEnums::INTERFACE_LIBRARY) { - std::string property = cmSystemTools::UpperCase(*ci); + std::string property = cmSystemTools::UpperCase(configName); property += "_POSTFIX"; - this->SetPropertyDefault(property, CM_NULLPTR); + this->SetPropertyDefault(property, nullptr); } } } @@ -365,16 +363,16 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, 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); + this->SetPropertyDefault("C_VISIBILITY_PRESET", nullptr); + this->SetPropertyDefault("CXX_VISIBILITY_PRESET", nullptr); + this->SetPropertyDefault("CUDA_VISIBILITY_PRESET", nullptr); + this->SetPropertyDefault("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); + this->SetPropertyDefault("ANDROID_GUI", nullptr); + this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", nullptr); + this->SetPropertyDefault("ENABLE_EXPORTS", nullptr); } if (this->TargetTypeValue == cmStateEnums::SHARED_LIBRARY || this->TargetTypeValue == cmStateEnums::MODULE_LIBRARY) { @@ -382,12 +380,12 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, } if (this->TargetTypeValue == cmStateEnums::SHARED_LIBRARY || this->TargetTypeValue == cmStateEnums::EXECUTABLE) { - this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", CM_NULLPTR); + this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", nullptr); } if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY && this->GetType() != cmStateEnums::UTILITY) { - this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", CM_NULLPTR); + this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", nullptr); } // Record current policies for later use. @@ -403,8 +401,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY && this->GetType() != cmStateEnums::UTILITY) { - this->SetPropertyDefault("JOB_POOL_COMPILE", CM_NULLPTR); - this->SetPropertyDefault("JOB_POOL_LINK", CM_NULLPTR); + this->SetPropertyDefault("JOB_POOL_COMPILE", nullptr); + this->SetPropertyDefault("JOB_POOL_LINK", nullptr); } } @@ -427,7 +425,7 @@ cmListFileBacktrace const* cmTarget::GetUtilityBacktrace( std::map::const_iterator i = this->UtilityBacktraces.find(u); if (i == this->UtilityBacktraces.end()) { - return CM_NULLPTR; + return nullptr; } return &i->second; @@ -479,9 +477,7 @@ void cmTarget::AddSources(std::vector const& srcs) { std::string srcFiles; const char* sep = ""; - for (std::vector::const_iterator i = srcs.begin(); - i != srcs.end(); ++i) { - std::string filename = *i; + for (auto filename : srcs) { const char* src = filename.c_str(); if (!(src[0] == '$' && src[1] == '<')) { @@ -545,7 +541,7 @@ cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s) { std::string src = this->ProcessSourceItemCMP0049(s); if (!s.empty() && src.empty()) { - return CM_NULLPTR; + return nullptr; } return this->AddSource(src); } @@ -595,8 +591,9 @@ public: { std::vector files; cmSystemTools::ExpandListArgument(entry, files); - std::vector locations(files.size()); - std::transform(files.begin(), files.end(), locations.begin(), + std::vector 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(), @@ -616,7 +613,7 @@ cmSourceFile* cmTarget::AddSource(const std::string& src) this->Internal->SourceBacktraces.push_back(lfbt); } if (cmGeneratorExpression::Find(src) != std::string::npos) { - return CM_NULLPTR; + return nullptr; } return this->Makefile->GetOrCreateSource(src); } @@ -710,12 +707,10 @@ 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 > 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; + for (auto const& cmd : this->TLLCommands) { + if (cmd.first == sig) { + cmListFileContext lfc = cmd.second; lfc.FilePath = converter.ConvertToRelativePath( this->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath); s << " * " << lfc << std::endl; @@ -1178,7 +1173,7 @@ const char* cmTarget::GetComputedProperty( const char* cmTarget::GetProperty(const std::string& prop) const { - static CM_UNORDERED_SET specialProps; + static std::unordered_set specialProps; #define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP MAKE_STATIC_PROP(LINK_LIBRARIES); MAKE_STATIC_PROP(TYPE); @@ -1210,7 +1205,7 @@ 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; + return nullptr; } static std::string output; @@ -1223,7 +1218,7 @@ const char* cmTarget::GetProperty(const std::string& prop) const } if (prop == propINCLUDE_DIRECTORIES) { if (this->Internal->IncludeDirectoriesEntries.empty()) { - return CM_NULLPTR; + return nullptr; } static std::string output; @@ -1232,7 +1227,7 @@ const char* cmTarget::GetProperty(const std::string& prop) const } if (prop == propCOMPILE_FEATURES) { if (this->Internal->CompileFeaturesEntries.empty()) { - return CM_NULLPTR; + return nullptr; } static std::string output; @@ -1241,7 +1236,7 @@ const char* cmTarget::GetProperty(const std::string& prop) const } if (prop == propCOMPILE_OPTIONS) { if (this->Internal->CompileOptionsEntries.empty()) { - return CM_NULLPTR; + return nullptr; } static std::string output; @@ -1250,7 +1245,7 @@ const char* cmTarget::GetProperty(const std::string& prop) const } if (prop == propCOMPILE_DEFINITIONS) { if (this->Internal->CompileDefinitionsEntries.empty()) { - return CM_NULLPTR; + return nullptr; } static std::string output; @@ -1259,7 +1254,7 @@ const char* cmTarget::GetProperty(const std::string& prop) const } if (prop == propMANUALLY_ADDED_DEPENDENCIES) { if (this->Utilities.empty()) { - return CM_NULLPTR; + return nullptr; } static std::string output; @@ -1397,8 +1392,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 && @@ -1535,7 +1530,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 +1577,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. diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 1f00c0155..940e26c69 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -19,7 +20,6 @@ #include "cmPropertyMap.h" #include "cmStateTypes.h" #include "cmTargetLinkLibraryType.h" -#include "cm_unordered_map.hxx" class cmGlobalGenerator; class cmMakefile; @@ -184,7 +184,7 @@ public: * 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); + void AddUtility(const std::string& u, cmMakefile* makefile = nullptr); ///! Get the utilities used by this target std::set const& GetUtilities() const { return this->Utilities; } cmListFileBacktrace const* GetUtilityBacktrace(const std::string& u) const; @@ -297,7 +297,7 @@ private: std::vector PreBuildCommands; std::vector PreLinkCommands; std::vector PostBuildCommands; - std::vector > TLLCommands; + std::vector> TLLCommands; LinkLibraryVectorType OriginalLinkLibraries; cmMakefile* Makefile; cmTargetInternalPointer Internal; @@ -323,7 +323,7 @@ private: cmListFileBacktrace Backtrace; }; -typedef CM_UNORDERED_MAP cmTargets; +typedef std::unordered_map cmTargets; class cmTargetSet : public std::set { diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx index 008d1a210..d159d4178 100644 --- a/Source/cmTargetCompileDefinitionsCommand.cxx +++ b/Source/cmTargetCompileDefinitionsCommand.cxx @@ -41,12 +41,11 @@ std::string cmTargetCompileDefinitionsCommand::Join( { std::string defs; std::string sep; - for (std::vector::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.c_str(), "-D")) { + defs += sep + it.substr(2); } else { - defs += sep + *it; + defs += sep + it; } sep = ";"; } diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h index 11abf571c..f91045225 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 #include @@ -20,26 +20,23 @@ 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 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 HandleImportedTarget(const std::string& tgt) override; + void HandleMissingTarget(const std::string& name) override; bool HandleDirectContent(cmTarget* tgt, const std::vector& content, - bool prepend, bool system) CM_OVERRIDE; - std::string Join(const std::vector& content) CM_OVERRIDE; + bool prepend, bool system) override; + std::string Join(const std::vector& content) override; }; #endif diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx index 1b6c00887..722bbe56c 100644 --- a/Source/cmTargetCompileFeaturesCommand.cxx +++ b/Source/cmTargetCompileFeaturesCommand.cxx @@ -45,10 +45,9 @@ std::string cmTargetCompileFeaturesCommand::Join( bool cmTargetCompileFeaturesCommand::HandleDirectContent( cmTarget* tgt, const std::vector& content, bool, bool) { - for (std::vector::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; } diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h index 990868004..444d26069 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 #include @@ -16,19 +16,19 @@ class cmTarget; class cmTargetCompileFeaturesCommand : public cmTargetPropCommandBase { - cmCommand* Clone() CM_OVERRIDE { return new cmTargetCompileFeaturesCommand; } + cmCommand* Clone() override { return new cmTargetCompileFeaturesCommand; } bool InitialPass(std::vector 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 HandleImportedTarget(const std::string& tgt) override; + void HandleMissingTarget(const std::string& name) override; bool HandleDirectContent(cmTarget* tgt, const std::vector& content, - bool prepend, bool system) CM_OVERRIDE; - std::string Join(const std::vector& content) CM_OVERRIDE; + bool prepend, bool system) override; + std::string Join(const std::vector& content) override; }; #endif diff --git a/Source/cmTargetCompileOptionsCommand.h b/Source/cmTargetCompileOptionsCommand.h index b5408f7cb..3fab238f2 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 #include @@ -20,23 +20,23 @@ 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 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 HandleImportedTarget(const std::string& tgt) override; + void HandleMissingTarget(const std::string& name) override; bool HandleDirectContent(cmTarget* tgt, const std::vector& content, - bool prepend, bool system) CM_OVERRIDE; - std::string Join(const std::vector& content) CM_OVERRIDE; + bool prepend, bool system) override; + std::string Join(const std::vector& content) override; }; #endif diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx index 65a31490f..4646c7ee1 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.cxx +++ b/Source/cmTargetIncludeDirectoriesCommand.cxx @@ -47,13 +47,12 @@ std::string cmTargetIncludeDirectoriesCommand::Join( std::string sep; std::string prefix = this->Makefile->GetCurrentSourceDirectory() + std::string("/"); - for (std::vector::const_iterator it = content.begin(); - it != content.end(); ++it) { - if (cmSystemTools::FileIsFullPath(it->c_str()) || - cmGeneratorExpression::Find(*it) == 0) { - dirs += sep + *it; + for (std::string const& it : content) { + if (cmSystemTools::FileIsFullPath(it.c_str()) || + cmGeneratorExpression::Find(it) == 0) { + dirs += sep + it; } else { - dirs += sep + prefix + *it; + dirs += sep + prefix + it; } sep = ";"; } @@ -70,13 +69,12 @@ bool cmTargetIncludeDirectoriesCommand::HandleDirectContent( std::string prefix = this->Makefile->GetCurrentSourceDirectory() + std::string("/"); std::set sdirs; - for (std::vector::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.c_str()) || + cmGeneratorExpression::Find(it) == 0) { + sdirs.insert(it); } else { - sdirs.insert(prefix + *it); + sdirs.insert(prefix + it); } } tgt->AddSystemIncludeDirectories(sdirs); diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h index 374a867dc..27a2f437a 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 #include @@ -20,30 +20,27 @@ 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 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 HandleImportedTarget(const std::string& tgt) override; + void HandleMissingTarget(const std::string& name) override; bool HandleDirectContent(cmTarget* tgt, const std::vector& content, - bool prepend, bool system) CM_OVERRIDE; + bool prepend, bool system) override; void HandleInterfaceContent(cmTarget* tgt, const std::vector& content, - bool prepend, bool system) CM_OVERRIDE; + bool prepend, bool system) override; - std::string Join(const std::vector& content) CM_OVERRIDE; + std::string Join(const std::vector& content) override; }; #endif diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index e17303645..dda0464de 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -95,7 +95,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass( if (this->Target->GetType() == cmStateEnums::UTILITY) { std::ostringstream e; - const char* modal = CM_NULLPTR; + const char* modal = nullptr; cmake::MessageType messageType = cmake::AUTHOR_WARNING; switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0039)) { case cmPolicies::WARN: @@ -311,7 +311,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, if (!this->Target->PushTLLCommandTrace( sig, this->Makefile->GetExecutionContext())) { std::ostringstream e; - const char* modal = CM_NULLPTR; + const char* modal = nullptr; cmake::MessageType messageType = cmake::AUTHOR_WARNING; switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0023)) { case cmPolicies::WARN: @@ -366,6 +366,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, if (tgt && (tgt->GetType() != cmStateEnums::STATIC_LIBRARY) && (tgt->GetType() != cmStateEnums::SHARED_LIBRARY) && + (tgt->GetType() != cmStateEnums::UNKNOWN_LIBRARY) && (tgt->GetType() != cmStateEnums::INTERFACE_LIBRARY) && !tgt->IsExecutableWithExports()) { std::ostringstream e; @@ -428,10 +429,9 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, // 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::const_iterator i = debugConfigs.begin(); - i != debugConfigs.end(); ++i) { + for (std::string const& dc : debugConfigs) { prop = "LINK_INTERFACE_LIBRARIES_"; - prop += *i; + prop += dc; this->Target->AppendProperty(prop, lib.c_str()); } } @@ -441,10 +441,9 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, // Make sure the DEBUG configuration interfaces exist so that the // general one will not be used as a fall-back. - for (std::vector::const_iterator i = debugConfigs.begin(); - i != debugConfigs.end(); ++i) { + for (std::string const& dc : debugConfigs) { prop = "LINK_INTERFACE_LIBRARIES_"; - prop += *i; + prop += dc; if (!this->Target->GetProperty(prop)) { this->Target->SetProperty(prop, ""); } diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h index 3fd20accd..f41af49d2 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 #include @@ -27,14 +27,14 @@ 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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; private: void LinkLibraryTypeSpecifierWarning(int left, int right); diff --git a/Source/cmTargetPropertyComputer.cxx b/Source/cmTargetPropertyComputer.cxx index a57bc5aea..1d2520d4b 100644 --- a/Source/cmTargetPropertyComputer.cxx +++ b/Source/cmTargetPropertyComputer.cxx @@ -4,11 +4,11 @@ #include "cmTargetPropertyComputer.h" #include +#include #include "cmMessenger.h" #include "cmPolicies.h" #include "cmStateSnapshot.h" -#include "cm_unordered_set.hxx" #include "cmake.h" bool cmTargetPropertyComputer::HandleLocationPropertyPolicy( @@ -16,7 +16,7 @@ bool cmTargetPropertyComputer::HandleLocationPropertyPolicy( cmListFileBacktrace const& context) { std::ostringstream e; - const char* modal = CM_NULLPTR; + const char* modal = nullptr; cmake::MessageType messageType = cmake::AUTHOR_WARNING; switch (context.GetBottom().GetPolicy(cmPolicies::CMP0026)) { case cmPolicies::WARN: @@ -49,7 +49,7 @@ bool cmTargetPropertyComputer::WhiteListedInterfaceProperty( if (cmHasLiteralPrefix(prop, "INTERFACE_")) { return true; } - static CM_UNORDERED_SET builtIns; + static std::unordered_set builtIns; if (builtIns.empty()) { builtIns.insert("COMPATIBLE_INTERFACE_BOOL"); builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX"); @@ -66,12 +66,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; } diff --git a/Source/cmTargetPropertyComputer.h b/Source/cmTargetPropertyComputer.h index 94688e313..97e4fba2c 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,7 +79,7 @@ private: if (!tgt->IsImported() && !HandleLocationPropertyPolicy(tgt->GetName(), messenger, context)) { - return CM_NULLPTR; + return nullptr; } const char* configName = prop.c_str() + 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 diff --git a/Source/cmTargetSourcesCommand.h b/Source/cmTargetSourcesCommand.h index 09ba72915..0639e980e 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 #include @@ -20,24 +20,24 @@ 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 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 HandleImportedTarget(const std::string& tgt) override; + void HandleMissingTarget(const std::string& name) override; bool HandleDirectContent(cmTarget* tgt, const std::vector& content, - bool prepend, bool system) CM_OVERRIDE; + bool prepend, bool system) override; - std::string Join(const std::vector& content) CM_OVERRIDE; + std::string Join(const std::vector& content) override; }; #endif diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index be4b37847..78ca6bca3 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmTestGenerator.h" -#include #include #include @@ -23,7 +22,7 @@ cmTestGenerator::cmTestGenerator( { this->ActionsPerConfig = !test->GetOldStyle(); this->TestGenerated = false; - this->LG = CM_NULLPTR; + this->LG = nullptr; } cmTestGenerator::~cmTestGenerator() @@ -80,7 +79,7 @@ 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) { std::vector emulatorWithArgs; cmSystemTools::ExpandListArgument(emulator, emulatorWithArgs); std::string emulatorExe(emulatorWithArgs[0]); @@ -114,10 +113,10 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, 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 << " " + for (auto const& i : pm) { + os << " " << i.first << " " << cmOutputConverter::EscapeForCMake( - ge.Parse(i->second.GetValue())->Evaluate(this->LG, config)); + ge.Parse(i.second.GetValue())->Evaluate(this->LG, config)); } os << ")" << std::endl; } @@ -154,15 +153,14 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout, Indent indent) // 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 : *argit) { // 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 << "\""; } @@ -173,9 +171,9 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout, Indent indent) 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()); + for (auto const& i : pm) { + fout << " " << i.first << " " + << cmOutputConverter::EscapeForCMake(i.second.GetValue()); } fout << ")" << std::endl; } diff --git a/Source/cmTestGenerator.h b/Source/cmTestGenerator.h index b2273050f..1ca61c210 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" @@ -26,17 +26,17 @@ public: cmTestGenerator(cmTest* test, std::vector const& configurations = std::vector()); - ~cmTestGenerator() CM_OVERRIDE; + ~cmTestGenerator() override; void Compute(cmLocalGenerator* lg); 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..9fb79d945 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 #include #include @@ -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()) { @@ -56,14 +55,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(); } @@ -124,7 +123,9 @@ std::string cmTimestamp::AddTimestampComponent(char flag, switch (flag) { case 'a': + case 'A': case 'b': + case 'B': case 'd': case 'H': case 'I': diff --git a/Source/cmTryCompileCommand.h b/Source/cmTryCompileCommand.h index 483654822..fbe0d78b6 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 07e20e62f..dcaa4939e 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -33,11 +33,11 @@ bool cmTryRunCommand::InitialPass(std::vector const& argv, // build an arg list for TryCompile and extract the runArgs, std::vector 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; @@ -125,9 +125,8 @@ bool cmTryRunCommand::InitialPass(std::vector const& argv, 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); } @@ -189,7 +188,7 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, } int timeout = 0; bool worked = cmSystemTools::RunSingleCommand( - finalCommand.c_str(), out, out, &retVal, CM_NULLPTR, + finalCommand.c_str(), out, out, &retVal, nullptr, cmSystemTools::OUTPUT_NONE, timeout); // set the run var char retChar[1000]; @@ -233,7 +232,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) == nullptr) { // if the variables doesn't exist, create it with a helpful error text // and mark it as advanced std::string comment; @@ -255,8 +254,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 != nullptr) { + if (this->Makefile->GetDefinition(internalRunOutputName) == nullptr) { // if the variables doesn't exist, create it with a helpful error text // and mark it as advanced std::string comment; @@ -304,7 +303,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 != nullptr) { comment += internalRunOutputName; comment += "\n contains the text the executable " @@ -335,7 +334,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 != nullptr) { file << "set( " << internalRunOutputName << " \n \"" << this->Makefile->GetDefinition(internalRunOutputName) << "\"\n CACHE STRING \"Output from TRY_RUN\" FORCE)\n\n"; @@ -348,7 +347,7 @@ 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 != nullptr) { errorMessage += " " + internalRunOutputName + " (advanced)\n"; } errorMessage += detailsString; @@ -356,7 +355,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs, return; } - if (out != CM_NULLPTR) { + if (out != nullptr) { (*out) = this->Makefile->GetDefinition(internalRunOutputName); } } diff --git a/Source/cmTryRunCommand.h b/Source/cmTryRunCommand.h index c27b026ad..b632ef580 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 #include @@ -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 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..7154881a4 100644 --- a/Source/cmUnexpectedCommand.h +++ b/Source/cmUnexpectedCommand.h @@ -3,7 +3,7 @@ #ifndef cmUnexpectedCommand_h #define cmUnexpectedCommand_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -21,13 +21,13 @@ public: { } - cmCommand* Clone() CM_OVERRIDE + cmCommand* Clone() override { return new cmUnexpectedCommand(this->Name, this->Error); } bool InitialPass(std::vector 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..18bbdd748 100644 --- a/Source/cmUnsetCommand.cxx +++ b/Source/cmUnsetCommand.cxx @@ -46,7 +46,7 @@ bool cmUnsetCommand::InitialPass(std::vector 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmUseMangledMesaCommand.cxx b/Source/cmUseMangledMesaCommand.cxx index 07095b137..c04a68327 100644 --- a/Source/cmUseMangledMesaCommand.cxx +++ b/Source/cmUseMangledMesaCommand.cxx @@ -38,11 +38,10 @@ bool cmUseMangledMesaCommand::InitialPass(std::vector const& args, return false; } cmSystemTools::MakeDirectory(destDir); - for (std::vector::iterator i = files.begin(); i != files.end(); - ++i) { + for (std::string const& f : files) { std::string path = inputDir; path += "/"; - path += *i; + path += f; this->CopyAndFullPathMesaHeader(path.c_str(), destDir); } diff --git a/Source/cmUseMangledMesaCommand.h b/Source/cmUseMangledMesaCommand.h index 511882989..78f86167b 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 #include @@ -15,9 +15,9 @@ class cmExecutionStatus; class cmUseMangledMesaCommand : public cmCommand { public: - cmCommand* Clone() CM_OVERRIDE { return new cmUseMangledMesaCommand; } + cmCommand* Clone() override { return new cmUseMangledMesaCommand; } bool InitialPass(std::vector const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; protected: void CopyAndFullPathMesaHeader(const char* source, const char* outdir); diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx index eabd7ef31..0ce437c1a 100644 --- a/Source/cmUtilitySourceCommand.cxx +++ b/Source/cmUtilitySourceCommand.cxx @@ -33,7 +33,7 @@ bool cmUtilitySourceCommand::InitialPass(std::vector const& args, 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; @@ -45,7 +45,7 @@ bool cmUtilitySourceCommand::InitialPass(std::vector const& args, } else { cmState* state = this->Makefile->GetState(); haveCacheValue = - (cacheValue && (strstr(cacheValue, "(IntDir)") == CM_NULLPTR || + (cacheValue && (strstr(cacheValue, "(IntDir)") == nullptr || (intDir && strcmp(intDir, "$(IntDir)") == 0)) && (state->GetCacheMajorVersion() != 0 && state->GetCacheMinorVersion() != 0)); 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmVS10CLFlagTable.h b/Source/cmVS10CLFlagTable.h index dbd760ed1..df4d58c03 100644 --- a/Source/cmVS10CLFlagTable.h +++ b/Source/cmVS10CLFlagTable.h @@ -70,7 +70,8 @@ static cmVS7FlagTable cmVS10CLFlagTable[] = { cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "PrecompiledHeader", "Yu", "Use", "Use", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "PrecompiledHeader", "", "Not Using Precompiled Headers", "NotUsing", 0 }, + { "PrecompiledHeader", "Y-", "Not Using Precompiled Headers", "NotUsing", + 0 }, { "AssemblerOutput", "", "No Listing", "NoListing", 0 }, { "AssemblerOutput", "FA", "Assembly-Only Listing", "AssemblyCode", 0 }, diff --git a/Source/cmVS10CSharpFlagTable.h b/Source/cmVS10CSharpFlagTable.h index 493ec2b12..18d587c50 100644 --- a/Source/cmVS10CSharpFlagTable.h +++ b/Source/cmVS10CSharpFlagTable.h @@ -25,7 +25,8 @@ static cmVS7FlagTable cmVS10CSharpFlagTable[] = { { "ApplicationIcon", "win32icon", "", "", cmIDEFlagTable::UserValueRequired }, - { "Win32Manifest", "win32manifest:", "", "true", 0 }, + { "ApplicationManifest", "win32manifest:", "", "", + cmIDEFlagTable::UserValueRequired }, { "NoWin32Manifest", "nowin32manifest", "", "true", 0 }, diff --git a/Source/cmVS10LinkFlagTable.h b/Source/cmVS10LinkFlagTable.h index c30ea9a66..6a0313a2f 100644 --- a/Source/cmVS10LinkFlagTable.h +++ b/Source/cmVS10LinkFlagTable.h @@ -29,6 +29,8 @@ static cmVS7FlagTable cmVS10LinkFlagTable[] = { { "CreateHotPatchableImage", "FUNCTIONPADMIN:16", "Itanium Image Only", "ItaniumImage", 0 }, + // correct flags for uac should be /MANIFESTUAC, but some projects already + // use this bug to access uac field, so keep these for compatibility { "UACExecutionLevel", "level='asInvoker'", "asInvoker", "AsInvoker", 0 }, { "UACExecutionLevel", "level='highestAvailable'", "highestAvailable", "HighestAvailable", 0 }, @@ -123,8 +125,12 @@ static cmVS7FlagTable cmVS10LinkFlagTable[] = { { "GenerateManifest", "MANIFEST:NO", "", "false", 0 }, { "GenerateManifest", "MANIFEST", "", "true", 0 }, { "AllowIsolation", "ALLOWISOLATION:NO", "", "false", 0 }, + + // correct flags for uac should be /MANIFESTUAC, but some projects already + // use this bug to access uac field, so keep these for compatibility { "UACUIAccess", "uiAccess='false'", "", "false", 0 }, { "UACUIAccess", "uiAccess='true'", "", "true", 0 }, + { "GenerateDebugInformation", "DEBUG", "", "true", cmVS7FlagTable::CaseInsensitive }, { "MapExports", "MAPINFO:EXPORTS", "", "true", 0 }, @@ -162,11 +168,8 @@ static cmVS7FlagTable cmVS10LinkFlagTable[] = { { "LinkDLL", "DLL", "", "true", 0 }, // Bool Properties With Argument - { "EnableUAC", "MANIFESTUAC:NO", "", "false", 0 }, - { "EnableUAC", "MANIFESTUAC:", "", "true", - cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "UACUIAccess", "MANIFESTUAC:", "Enable User Account Control (UAC)", "", - cmVS7FlagTable::UserValueRequired }, + { "EnableUAC", "MANIFESTUAC:", "", "", + cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SpaceAppendable }, { "GenerateMapFile", "MAP", "", "true", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "MapFileName", "MAP:", "Generate Map File", "", diff --git a/Source/cmVS11CLFlagTable.h b/Source/cmVS11CLFlagTable.h index 75317093f..d156938e1 100644 --- a/Source/cmVS11CLFlagTable.h +++ b/Source/cmVS11CLFlagTable.h @@ -74,7 +74,8 @@ static cmVS7FlagTable cmVS11CLFlagTable[] = { cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "PrecompiledHeader", "Yu", "Use", "Use", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "PrecompiledHeader", "", "Not Using Precompiled Headers", "NotUsing", 0 }, + { "PrecompiledHeader", "Y-", "Not Using Precompiled Headers", "NotUsing", + 0 }, { "AssemblerOutput", "", "No Listing", "NoListing", 0 }, { "AssemblerOutput", "FA", "Assembly-Only Listing", "AssemblyCode", 0 }, diff --git a/Source/cmVS11CSharpFlagTable.h b/Source/cmVS11CSharpFlagTable.h index 71870b698..e3ba83c2c 100644 --- a/Source/cmVS11CSharpFlagTable.h +++ b/Source/cmVS11CSharpFlagTable.h @@ -25,7 +25,8 @@ static cmVS7FlagTable cmVS11CSharpFlagTable[] = { { "ApplicationIcon", "win32icon", "", "", cmIDEFlagTable::UserValueRequired }, - { "Win32Manifest", "win32manifest:", "", "true", 0 }, + { "ApplicationManifest", "win32manifest:", "", "", + cmIDEFlagTable::UserValueRequired }, { "NoWin32Manifest", "nowin32manifest", "", "true", 0 }, diff --git a/Source/cmVS11LinkFlagTable.h b/Source/cmVS11LinkFlagTable.h index 1b3a046f6..24ba8fded 100644 --- a/Source/cmVS11LinkFlagTable.h +++ b/Source/cmVS11LinkFlagTable.h @@ -29,6 +29,8 @@ static cmVS7FlagTable cmVS11LinkFlagTable[] = { { "CreateHotPatchableImage", "FUNCTIONPADMIN:16", "Itanium Image Only", "ItaniumImage", 0 }, + // correct flags for uac should be /MANIFESTUAC, but some projects already + // use this bug to access uac field, so keep these for compatibility { "UACExecutionLevel", "level='asInvoker'", "asInvoker", "AsInvoker", 0 }, { "UACExecutionLevel", "level='highestAvailable'", "highestAvailable", "HighestAvailable", 0 }, @@ -135,8 +137,12 @@ static cmVS7FlagTable cmVS11LinkFlagTable[] = { { "GenerateManifest", "MANIFEST:NO", "", "false", 0 }, { "GenerateManifest", "MANIFEST", "", "true", 0 }, { "AllowIsolation", "ALLOWISOLATION:NO", "", "false", 0 }, + + // correct flags for uac should be /MANIFESTUAC, but some projects already + // use this bug to access uac field, so keep these for compatibility { "UACUIAccess", "uiAccess='false'", "", "false", 0 }, { "UACUIAccess", "uiAccess='true'", "", "true", 0 }, + { "ManifestEmbed", "manifest:embed", "", "true", 0 }, { "GenerateDebugInformation", "DEBUG", "", "true", cmVS7FlagTable::CaseInsensitive }, @@ -179,11 +185,8 @@ static cmVS7FlagTable cmVS11LinkFlagTable[] = { { "LinkDLL", "DLL", "", "true", 0 }, // Bool Properties With Argument - { "EnableUAC", "MANIFESTUAC:NO", "", "false", 0 }, - { "EnableUAC", "MANIFESTUAC:", "", "true", - cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "UACUIAccess", "MANIFESTUAC:", "Enable User Account Control (UAC)", "", - cmVS7FlagTable::UserValueRequired }, + { "EnableUAC", "MANIFESTUAC:", "", "", + cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SpaceAppendable }, { "GenerateMapFile", "MAP", "", "true", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "MapFileName", "MAP:", "Generate Map File", "", diff --git a/Source/cmVS12CLFlagTable.h b/Source/cmVS12CLFlagTable.h index 9515c91b8..a4f251808 100644 --- a/Source/cmVS12CLFlagTable.h +++ b/Source/cmVS12CLFlagTable.h @@ -78,7 +78,8 @@ static cmVS7FlagTable cmVS12CLFlagTable[] = { cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "PrecompiledHeader", "Yu", "Use", "Use", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "PrecompiledHeader", "", "Not Using Precompiled Headers", "NotUsing", 0 }, + { "PrecompiledHeader", "Y-", "Not Using Precompiled Headers", "NotUsing", + 0 }, { "AssemblerOutput", "", "No Listing", "NoListing", 0 }, { "AssemblerOutput", "FA", "Assembly-Only Listing", "AssemblyCode", 0 }, diff --git a/Source/cmVS12CSharpFlagTable.h b/Source/cmVS12CSharpFlagTable.h index f98b1840d..f8db63670 100644 --- a/Source/cmVS12CSharpFlagTable.h +++ b/Source/cmVS12CSharpFlagTable.h @@ -25,7 +25,8 @@ static cmVS7FlagTable cmVS12CSharpFlagTable[] = { { "ApplicationIcon", "win32icon", "", "", cmIDEFlagTable::UserValueRequired }, - { "Win32Manifest", "win32manifest:", "", "true", 0 }, + { "ApplicationManifest", "win32manifest:", "", "", + cmIDEFlagTable::UserValueRequired }, { "NoWin32Manifest", "nowin32manifest", "", "true", 0 }, diff --git a/Source/cmVS12LinkFlagTable.h b/Source/cmVS12LinkFlagTable.h index 168c34c22..fc667c359 100644 --- a/Source/cmVS12LinkFlagTable.h +++ b/Source/cmVS12LinkFlagTable.h @@ -29,6 +29,8 @@ static cmVS7FlagTable cmVS12LinkFlagTable[] = { { "CreateHotPatchableImage", "FUNCTIONPADMIN:16", "Itanium Image Only", "ItaniumImage", 0 }, + // correct flags for uac should be /MANIFESTUAC, but some projects already + // use this bug to access uac field, so keep these for compatibility { "UACExecutionLevel", "level='asInvoker'", "asInvoker", "AsInvoker", 0 }, { "UACExecutionLevel", "level='highestAvailable'", "highestAvailable", "HighestAvailable", 0 }, @@ -135,8 +137,12 @@ static cmVS7FlagTable cmVS12LinkFlagTable[] = { { "GenerateManifest", "MANIFEST:NO", "", "false", 0 }, { "GenerateManifest", "MANIFEST", "", "true", 0 }, { "AllowIsolation", "ALLOWISOLATION:NO", "", "false", 0 }, + + // correct flags for uac should be /MANIFESTUAC, but some projects already + // use this bug to access uac field, so keep these for compatibility { "UACUIAccess", "uiAccess='false'", "", "false", 0 }, { "UACUIAccess", "uiAccess='true'", "", "true", 0 }, + { "ManifestEmbed", "manifest:embed", "", "true", 0 }, { "GenerateDebugInformation", "DEBUG", "", "true", cmVS7FlagTable::CaseInsensitive }, @@ -179,11 +185,8 @@ static cmVS7FlagTable cmVS12LinkFlagTable[] = { { "LinkDLL", "DLL", "", "true", 0 }, // Bool Properties With Argument - { "EnableUAC", "MANIFESTUAC:NO", "", "false", 0 }, - { "EnableUAC", "MANIFESTUAC:", "", "true", - cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "UACUIAccess", "MANIFESTUAC:", "Enable User Account Control (UAC)", "", - cmVS7FlagTable::UserValueRequired }, + { "EnableUAC", "MANIFESTUAC:", "", "", + cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SpaceAppendable }, { "GenerateMapFile", "MAP", "", "true", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "MapFileName", "MAP:", "Generate Map File", "", diff --git a/Source/cmVS140CLFlagTable.h b/Source/cmVS140CLFlagTable.h index 60b437974..2b89042c8 100644 --- a/Source/cmVS140CLFlagTable.h +++ b/Source/cmVS140CLFlagTable.h @@ -80,7 +80,8 @@ static cmVS7FlagTable cmVS140CLFlagTable[] = { cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "PrecompiledHeader", "Yu", "Use", "Use", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "PrecompiledHeader", "", "Not Using Precompiled Headers", "NotUsing", 0 }, + { "PrecompiledHeader", "Y-", "Not Using Precompiled Headers", "NotUsing", + 0 }, { "AssemblerOutput", "", "No Listing", "NoListing", 0 }, { "AssemblerOutput", "FA", "Assembly-Only Listing", "AssemblyCode", 0 }, diff --git a/Source/cmVS140CSharpFlagTable.h b/Source/cmVS140CSharpFlagTable.h index 256c35f70..055d5cba0 100644 --- a/Source/cmVS140CSharpFlagTable.h +++ b/Source/cmVS140CSharpFlagTable.h @@ -25,7 +25,8 @@ static cmVS7FlagTable cmVS140CSharpFlagTable[] = { { "ApplicationIcon", "win32icon", "", "", cmIDEFlagTable::UserValueRequired }, - { "Win32Manifest", "win32manifest:", "", "true", 0 }, + { "ApplicationManifest", "win32manifest:", "", "", + cmIDEFlagTable::UserValueRequired }, { "NoWin32Manifest", "nowin32manifest", "", "true", 0 }, diff --git a/Source/cmVS140LinkFlagTable.h b/Source/cmVS140LinkFlagTable.h index b9a4dc30a..7c9452abf 100644 --- a/Source/cmVS140LinkFlagTable.h +++ b/Source/cmVS140LinkFlagTable.h @@ -29,6 +29,8 @@ static cmVS7FlagTable cmVS140LinkFlagTable[] = { { "CreateHotPatchableImage", "FUNCTIONPADMIN:16", "Itanium Image Only", "ItaniumImage", 0 }, + // correct flags for uac should be /MANIFESTUAC, but some projects already + // use this bug to access uac field, so keep these for compatibility { "UACExecutionLevel", "level='asInvoker'", "asInvoker", "AsInvoker", 0 }, { "UACExecutionLevel", "level='highestAvailable'", "highestAvailable", "HighestAvailable", 0 }, @@ -148,8 +150,12 @@ static cmVS7FlagTable cmVS140LinkFlagTable[] = { { "GenerateManifest", "MANIFEST:NO", "", "false", 0 }, { "GenerateManifest", "MANIFEST", "", "true", 0 }, { "AllowIsolation", "ALLOWISOLATION:NO", "", "false", 0 }, + + // correct flags for uac should be /MANIFESTUAC, but some projects already + // use this bug to access uac field, so keep these for compatibility { "UACUIAccess", "uiAccess='false'", "", "false", 0 }, { "UACUIAccess", "uiAccess='true'", "", "true", 0 }, + { "ManifestEmbed", "manifest:embed", "", "true", 0 }, { "MapExports", "MAPINFO:EXPORTS", "", "true", 0 }, { "AssemblyDebug", "ASSEMBLYDEBUG:DISABLE", "", "false", 0 }, @@ -190,11 +196,8 @@ static cmVS7FlagTable cmVS140LinkFlagTable[] = { { "LinkDLL", "DLL", "", "true", 0 }, // Bool Properties With Argument - { "EnableUAC", "MANIFESTUAC:NO", "", "false", 0 }, - { "EnableUAC", "MANIFESTUAC:", "", "true", - cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "UACUIAccess", "MANIFESTUAC:", "Enable User Account Control (UAC)", "", - cmVS7FlagTable::UserValueRequired }, + { "EnableUAC", "MANIFESTUAC:", "", "", + cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SpaceAppendable }, { "GenerateMapFile", "MAP", "", "true", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "MapFileName", "MAP:", "Generate Map File", "", diff --git a/Source/cmVS141CLFlagTable.h b/Source/cmVS141CLFlagTable.h index f751fc875..c780d469a 100644 --- a/Source/cmVS141CLFlagTable.h +++ b/Source/cmVS141CLFlagTable.h @@ -79,6 +79,7 @@ static cmVS7FlagTable cmVS141CLFlagTable[] = { { "FloatingPointModel", "fp:strict", "Strict", "Strict", 0 }, { "FloatingPointModel", "fp:fast", "Fast", "Fast", 0 }, + { "LanguageStandard", "std:c++17", "ISO C++17 Standard", "stdcpp17", 0 }, { "LanguageStandard", "std:c++14", "ISO C++14 Standard", "stdcpp14", 0 }, { "LanguageStandard", "std:c++latest", "ISO C++ Latest Draft Standard", "stdcpplatest", 0 }, @@ -87,7 +88,8 @@ static cmVS7FlagTable cmVS141CLFlagTable[] = { cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "PrecompiledHeader", "Yu", "Use", "Use", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "PrecompiledHeader", "", "Not Using Precompiled Headers", "NotUsing", 0 }, + { "PrecompiledHeader", "Y-", "Not Using Precompiled Headers", "NotUsing", + 0 }, { "AssemblerOutput", "", "No Listing", "NoListing", 0 }, { "AssemblerOutput", "FA", "Assembly-Only Listing", "AssemblyCode", 0 }, diff --git a/Source/cmVS141CSharpFlagTable.h b/Source/cmVS141CSharpFlagTable.h index 85085817c..5de9bf33f 100644 --- a/Source/cmVS141CSharpFlagTable.h +++ b/Source/cmVS141CSharpFlagTable.h @@ -25,7 +25,8 @@ static cmVS7FlagTable cmVS141CSharpFlagTable[] = { { "ApplicationIcon", "win32icon", "", "", cmIDEFlagTable::UserValueRequired }, - { "Win32Manifest", "win32manifest:", "", "true", 0 }, + { "ApplicationManifest", "win32manifest:", "", "", + cmIDEFlagTable::UserValueRequired }, { "NoWin32Manifest", "nowin32manifest", "", "true", 0 }, diff --git a/Source/cmVS141LinkFlagTable.h b/Source/cmVS141LinkFlagTable.h index 8f0f1f42d..f159f7061 100644 --- a/Source/cmVS141LinkFlagTable.h +++ b/Source/cmVS141LinkFlagTable.h @@ -29,6 +29,8 @@ static cmVS7FlagTable cmVS141LinkFlagTable[] = { { "CreateHotPatchableImage", "FUNCTIONPADMIN:16", "Itanium Image Only", "ItaniumImage", 0 }, + // correct flags for uac should be /MANIFESTUAC, but some projects already + // use this bug to access uac field, so keep these for compatibility { "UACExecutionLevel", "level='asInvoker'", "asInvoker", "AsInvoker", 0 }, { "UACExecutionLevel", "level='highestAvailable'", "highestAvailable", "HighestAvailable", 0 }, @@ -87,6 +89,7 @@ static cmVS7FlagTable cmVS141LinkFlagTable[] = { { "TargetMachine", "", "Not Set", "NotSet", 0 }, { "TargetMachine", "MACHINE:ARM", "MachineARM", "MachineARM", 0 }, + { "TargetMachine", "MACHINE:ARM64", "MachineARM64", "MachineARM64", 0 }, { "TargetMachine", "MACHINE:EBC", "MachineEBC", "MachineEBC", 0 }, { "TargetMachine", "MACHINE:IA64", "MachineIA64", "MachineIA64", 0 }, { "TargetMachine", "MACHINE:MIPS", "MachineMIPS", "MachineMIPS", 0 }, @@ -149,8 +152,12 @@ static cmVS7FlagTable cmVS141LinkFlagTable[] = { { "GenerateManifest", "MANIFEST:NO", "", "false", 0 }, { "GenerateManifest", "MANIFEST", "", "true", 0 }, { "AllowIsolation", "ALLOWISOLATION:NO", "", "false", 0 }, + + // correct flags for uac should be /MANIFESTUAC, but some projects already + // use this bug to access uac field, so keep these for compatibility { "UACUIAccess", "uiAccess='false'", "", "false", 0 }, { "UACUIAccess", "uiAccess='true'", "", "true", 0 }, + { "ManifestEmbed", "manifest:embed", "", "true", 0 }, { "MapExports", "MAPINFO:EXPORTS", "", "true", 0 }, { "AssemblyDebug", "ASSEMBLYDEBUG:DISABLE", "", "false", 0 }, @@ -191,11 +198,8 @@ static cmVS7FlagTable cmVS141LinkFlagTable[] = { { "LinkDLL", "DLL", "", "true", 0 }, // Bool Properties With Argument - { "EnableUAC", "MANIFESTUAC:NO", "", "false", 0 }, - { "EnableUAC", "MANIFESTUAC:", "", "true", - cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, - { "UACUIAccess", "MANIFESTUAC:", "Enable User Account Control (UAC)", "", - cmVS7FlagTable::UserValueRequired }, + { "EnableUAC", "MANIFESTUAC:", "", "", + cmVS7FlagTable::UserValueRequired | cmVS7FlagTable::SpaceAppendable }, { "GenerateMapFile", "MAP", "", "true", cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue }, { "MapFileName", "MAP:", "Generate Map File", "", diff --git a/Source/cmVS14LibFlagTable.h b/Source/cmVS14LibFlagTable.h index 7fa713893..be4652c68 100644 --- a/Source/cmVS14LibFlagTable.h +++ b/Source/cmVS14LibFlagTable.h @@ -11,6 +11,7 @@ static cmVS7FlagTable cmVS14LibFlagTable[] = { 0 }, { "TargetMachine", "MACHINE:ARM", "MachineARM", "MachineARM", 0 }, + { "TargetMachine", "MACHINE:ARM64", "MachineARM64", "MachineARM64", 0 }, { "TargetMachine", "MACHINE:EBC", "MachineEBC", "MachineEBC", 0 }, { "TargetMachine", "MACHINE:IA64", "MachineIA64", "MachineIA64", 0 }, { "TargetMachine", "MACHINE:MIPS", "MachineMIPS", "MachineMIPS", 0 }, diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx index 7168f266c..ea13649c2 100644 --- a/Source/cmVSSetupHelper.cxx +++ b/Source/cmVSSetupHelper.cxx @@ -1,7 +1,10 @@ /* 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 @@ -41,14 +44,19 @@ 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"; +std::string VSInstanceInfo::GetInstallLocation() const +{ + std::string loc = cmsys::Encoding::ToNarrow(this->VSInstallLocation); + cmSystemTools::ConvertToUnixSlashes(loc); + return loc; +} + cmVSSetupAPIHelper::cmVSSetupAPIHelper() : setupConfig(NULL) , setupConfig2(NULL) @@ -90,11 +98,11 @@ bool cmVSSetupAPIHelper::IsWin81SDKInstalled() } bool cmVSSetupAPIHelper::CheckInstalledComponent( - SmartCOMPtr package, bool& bVCToolset, - bool& bWin10SDK, bool& bWin81SDK) + SmartCOMPtr 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 +115,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 +138,6 @@ bool cmVSSetupAPIHelper::CheckInstalledComponent( bool cmVSSetupAPIHelper::GetVSInstanceInfo( SmartCOMPtr pInstance, VSInstanceInfo& vsInstanceInfo) { - bool isVCToolSetInstalled = false; if (pInstance == NULL) return false; @@ -174,6 +176,23 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo( } } + // Check if a compiler is installed with this instance. + { + std::string const vcRoot = vsInstanceInfo.GetInstallLocation(); + std::string const 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; + } + } + // Reboot may have been required before the product package was registered // (last). if ((eRegistered & state) == eRegistered) { @@ -199,12 +218,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,18 +231,16 @@ 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; @@ -281,9 +297,7 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() if (isInstalled) { if (!envVSCommonToolsDir.empty()) { - std::string currentVSLocation(instanceInfo.VSInstallLocation.begin(), - instanceInfo.VSInstallLocation.end()); - cmSystemTools::ConvertToUnixSlashes(currentVSLocation); + std::string currentVSLocation = instanceInfo.GetInstallLocation(); currentVSLocation += "/Common7/Tools"; if (cmSystemTools::ComparePath(currentVSLocation, envVSCommonToolsDir)) { diff --git a/Source/cmVSSetupHelper.h b/Source/cmVSSetupHelper.h index d2f514c63..74a7ec04a 100644 --- a/Source/cmVSSetupHelper.h +++ b/Source/cmVSSetupHelper.h @@ -116,6 +116,8 @@ struct VSInstanceInfo ullVersion = 0; IsWin10SDKInstalled = IsWin81SDKInstalled = false; } + + std::string GetInstallLocation() const; }; class cmVSSetupAPIHelper @@ -134,8 +136,7 @@ private: bool GetVSInstanceInfo(SmartCOMPtr instance2, VSInstanceInfo& vsInstanceInfo); bool CheckInstalledComponent(SmartCOMPtr package, - bool& bVCToolset, bool& bWin10SDK, - bool& bWin81SDK); + bool& bWin10SDK, bool& bWin81SDK); int ChooseVSInstance(const std::vector& vecVSInstances); bool EnumerateAndChooseVSInstance(); 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 #include @@ -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 const& args, - cmExecutionStatus& status) CM_OVERRIDE; + cmExecutionStatus& status) override; }; #endif diff --git a/Source/cmVariableWatch.cxx b/Source/cmVariableWatch.cxx index 419e1a411..bd5d19c39 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 +#include #include +#include static const char* const cmVariableWatchAccessStrings[] = { "READ_ACCESS", "UNKNOWN_READ_ACCESS", "UNKNOWN_DEFINED_ACCESS", @@ -25,37 +23,27 @@ cmVariableWatch::cmVariableWatch() { } -template -void deleteAllSecond(typename C::value_type it) -{ - cmDeleteAll(it.second); -} - cmVariableWatch::~cmVariableWatch() { - std::for_each(this->WatchMap.begin(), this->WatchMap.end(), - deleteAllSecond); } bool cmVariableWatch::AddWatch(const std::string& variable, WatchMethod method, void* client_data /*=0*/, DeleteData delete_data /*=0*/) { - CM_AUTO_PTR p(new cmVariableWatch::Pair); + auto p = std::make_shared(); 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 +60,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 +73,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> 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..27d1b12df 100644 --- a/Source/cmVariableWatch.h +++ b/Source/cmVariableWatch.h @@ -6,6 +6,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include // IWYU pragma: keep #include #include @@ -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 @@ -67,9 +67,9 @@ protected: void* ClientData; DeleteData DeleteDataCall; Pair() - : Method(CM_NULLPTR) - , ClientData(CM_NULLPTR) - , DeleteDataCall(CM_NULLPTR) + : Method(nullptr) + , ClientData(nullptr) + , DeleteDataCall(nullptr) { } ~Pair() @@ -80,7 +80,7 @@ protected: } }; - typedef std::vector VectorOfPairs; + typedef std::vector> VectorOfPairs; typedef std::map StringToVectorOfPairs; StringToVectorOfPairs WatchMap; diff --git a/Source/cmVariableWatchCommand.cxx b/Source/cmVariableWatchCommand.cxx index 281850ecc..9930086f4 100644 --- a/Source/cmVariableWatchCommand.cxx +++ b/Source/cmVariableWatchCommand.cxx @@ -91,11 +91,9 @@ cmVariableWatchCommand::cmVariableWatchCommand() cmVariableWatchCommand::~cmVariableWatchCommand() { - std::set::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 #include @@ -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 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 WatchedVariables; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index dee153f6b..c61902ab6 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -15,7 +15,7 @@ #include "cmVisualStudioGeneratorOptions.h" #include "windows.h" -#include "cm_auto_ptr.hxx" +#include // IWYU pragma: keep static std::string cmVS10EscapeXML(std::string arg) { @@ -25,6 +25,12 @@ static std::string cmVS10EscapeXML(std::string arg) return arg; } +static std::string cmVS10EscapeQuotes(std::string arg) +{ + cmSystemTools::ReplaceString(arg, "\"", """); + return arg; +} + static std::string cmVS10EscapeComment(std::string comment) { // MSBuild takes the CDATA of a element and just @@ -79,7 +85,7 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( this->LocalGenerator = (cmLocalVisualStudio7Generator*)this->GeneratorTarget->GetLocalGenerator(); this->Name = this->GeneratorTarget->GetName(); - this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str()); + this->GUID = this->GlobalGenerator->GetGUID(this->Name); this->Platform = gg->GetPlatformName(); this->NsightTegra = gg->IsNsightTegra(); for (int i = 0; i < 4; ++i) { @@ -144,7 +150,7 @@ void cmVisualStudio10TargetGenerator::WritePlatformConfigTag( (*stream) << config << "|" << this->Platform; (*stream) << "'"; // handle special case for 32 bit C# targets - if (csproj == this->ProjectType && this->Platform == "Win32") { + if (this->ProjectType == csproj && this->Platform == "Win32") { (*stream) << " Or "; (*stream) << "'$(Configuration)|$(Platform)'=='"; (*stream) << config << "|x86"; @@ -292,7 +298,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteString("\n", 1); } - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { this->WriteProjectConfigurations(); } this->WriteString("\n", 1); @@ -309,7 +315,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES"); if (vsProjectTypes) { std::string tagName = "ProjectTypes"; - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { tagName = "ProjectTypeGuids"; } this->WriteString("", 2); @@ -401,11 +407,11 @@ void cmVisualStudio10TargetGenerator::Generate() continue; std::string globalKey = keyIt->substr(strlen(prefix)); // Skip invalid or separately-handled properties. - if (globalKey == "" || globalKey == "PROJECT_TYPES" || + if (globalKey.empty() || globalKey == "PROJECT_TYPES" || globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") { continue; } - const char* value = this->GeneratorTarget->GetProperty(keyIt->c_str()); + const char* value = this->GeneratorTarget->GetProperty(*keyIt); if (!value) continue; this->WriteString("<", 2); @@ -463,7 +469,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteProjectConfigurationValues(); - if (vcxproj == this->ProjectType) { + if (this->ProjectType == vcxproj) { this->WriteString("\n", 1); } this->WriteString("\n", 1); @@ -566,7 +572,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteString(import.c_str(), 2); } this->WriteString("\n", 1); - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { for (std::vector::const_iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { @@ -576,6 +582,18 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteEvents(*i); this->WriteString("\n", 1); } + // make sure custom commands are executed before build (if necessary) + this->WriteString("\n", 1); + this->WriteString("\n", 2); + for (std::set::const_iterator i = + this->CSharpCustomCommandNames.begin(); + i != this->CSharpCustomCommandNames.end(); ++i) { + this->WriteString(i->c_str(), 3); + (*this->BuildFileStream) << ";\n"; + } + this->WriteString("$(BuildDependsOn)\n", 3); + this->WriteString("\n", 2); + this->WriteString("\n", 1); } this->WriteString("", 0); // The groups are stored in a separate file for VS 10 @@ -596,7 +614,7 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences() ++i) { if (i->first.find("VS_DOTNET_REFERENCE_") == 0) { std::string name = i->first.substr(20); - if (name != "") { + if (!name.empty()) { std::string path = i->second.GetValue(); if (!cmsys::SystemTools::FileIsFullPath(path)) { path = std::string(this->GeneratorTarget->Target->GetMakefile() @@ -624,7 +642,7 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences() this->WriteDotNetReference(*ri, ""); } } - for (std::vector >::const_iterator i = + for (std::vector>::const_iterator i = hintReferences.begin(); i != hintReferences.end(); ++i) { this->WriteDotNetReference(i->first, i->second); @@ -657,9 +675,39 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReference( this->WriteString("", 3); (*this->BuildFileStream) << hint << "\n"; } + this->WriteDotNetReferenceCustomTags(ref); this->WriteString("\n", 2); } +void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags( + 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 CustomTags; + CustomTags tags; + cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties(); + for (cmPropertyMap::const_iterator i = props.begin(); i != props.end(); + ++i) { + 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 (CustomTags::const_iterator tag = tags.begin(); tag != tags.end(); + ++tag) { + this->WriteString("<", 3); + (*this->BuildFileStream) << tag->first << ">" + << cmVS10EscapeXML(tag->second) << "first << ">\n"; + } +} + void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() { std::vector resxObjs; @@ -675,7 +723,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() this->WriteString("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 @@ -688,7 +736,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() } (*this->BuildFileStream) << obj << "\">\n"; - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { this->WriteString("", 3); std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h"; (*this->BuildFileStream) << hFileName << "\n"; @@ -696,7 +744,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() for (std::vector::const_iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { - this->WritePlatformConfigTag("LogicalName", i->c_str(), 3); + this->WritePlatformConfigTag("LogicalName", *i, 3); if (this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE") || // Handle variant of VS_GLOBAL_ for RootNamespace. this->GeneratorTarget->GetProperty("VS_GLOBAL_RootNamespace")) { @@ -758,7 +806,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup() 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) { + if (p->first.find(propNamePrefix) == 0) { std::string tagName = p->first.substr(propNamePrefix.length()); if (!tagName.empty()) { std::string value = props.GetPropertyValue(p->first); @@ -798,7 +846,7 @@ void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup() } this->WriteSource(xamlType, *oi, ">\n"); - if (csproj == this->ProjectType && !this->InSourceBuild) { + if (this->ProjectType == csproj && !this->InSourceBuild) { // add tag to written XAML source if necessary const std::string srcDir = this->Makefile->GetCurrentSourceDirectory(); const std::string binDir = this->Makefile->GetCurrentBinaryDirectory(); @@ -914,10 +962,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues() for (std::vector::const_iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { - this->WritePlatformConfigTag("PropertyGroup", i->c_str(), 1, + this->WritePlatformConfigTag("PropertyGroup", *i, 1, " Label=\"Configuration\"", "\n"); - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { std::string configType = ""; if (const char* vsConfigurationType = this->GeneratorTarget->GetProperty("VS_CONFIGURATION_TYPE")) { @@ -1038,8 +1086,7 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged( this->WriteString("true\n", 2); } - std::string outDir = - this->GeneratorTarget->GetDirectory(config.c_str()) + "/"; + std::string outDir = this->GeneratorTarget->GetDirectory(config) + "/"; this->ConvertToWindowsSlash(outDir); this->WriteString("", 2); (*this->BuildFileStream) << cmVS10EscapeXML(outDir) << "\n"; @@ -1119,6 +1166,7 @@ void cmVisualStudio10TargetGenerator::WriteNsightTegraConfigurationValues( void cmVisualStudio10TargetGenerator::WriteCustomCommands() { this->SourcesVisited.clear(); + this->CSharpCustomCommandNames.clear(); std::vector customCommands; this->GeneratorTarget->GetCustomCommands(customCommands, ""); for (std::vector::const_iterator si = @@ -1140,9 +1188,14 @@ void cmVisualStudio10TargetGenerator::WriteCustomCommand( } } if (cmCustomCommand const* command = sf->GetCustomCommand()) { - this->WriteString("\n", 1); + // C# projects write their within WriteCustomRule() + if (this->ProjectType != csproj) { + this->WriteString("\n", 1); + } this->WriteCustomRule(sf, *command); - this->WriteString("\n", 1); + if (this->ProjectType != csproj) { + this->WriteString("\n", 1); + } } } } @@ -1177,8 +1230,20 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( } cmLocalVisualStudio7Generator* lg = this->LocalGenerator; - this->WriteSource("CustomBuild", source, ">\n"); - + if (this->ProjectType != csproj) { + this->WriteSource("CustomBuild", source, ">\n"); + } else { + this->WriteString("\n", 1); + std::string link; + this->GetCSharpSourceLink(source, link); + this->WriteSource("None", source, ">\n"); + if (!link.empty()) { + this->WriteString("", 3); + (*this->BuildFileStream) << link << "\n"; + } + this->WriteString("\n", 2); + this->WriteString("\n", 1); + } for (std::vector::const_iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { @@ -1186,41 +1251,90 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule( 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) << "\n"; - this->WritePlatformConfigTag("Command", i->c_str(), 3); - (*this->BuildFileStream) << script << "\n"; - this->WritePlatformConfigTag("AdditionalInputs", i->c_str(), 3); - - (*this->BuildFileStream) << cmVS10EscapeXML(source->GetFullPath()); + // input files for custom command + std::stringstream inputs; + inputs << cmVS10EscapeXML(source->GetFullPath()); for (std::vector::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)) { + if (this->LocalGenerator->GetRealDependency(*d, *i, dep)) { this->ConvertToWindowsSlash(dep); - (*this->BuildFileStream) << ";" << cmVS10EscapeXML(dep); + inputs << ";" << cmVS10EscapeXML(dep); } } - (*this->BuildFileStream) << ";%(AdditionalInputs)\n"; - this->WritePlatformConfigTag("Outputs", i->c_str(), 3); + // output files for custom command + std::stringstream outputs; const char* sep = ""; for (std::vector::const_iterator o = ccg.GetOutputs().begin(); o != ccg.GetOutputs().end(); ++o) { std::string out = *o; this->ConvertToWindowsSlash(out); - (*this->BuildFileStream) << sep << cmVS10EscapeXML(out); + outputs << sep << cmVS10EscapeXML(out); sep = ";"; } - (*this->BuildFileStream) << "\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\n"; + if (this->ProjectType == csproj) { + std::string name = "CustomCommand_" + *i + "_" + + cmSystemTools::ComputeStringMD5(sourcePath); + std::string inputs_s = inputs.str(); + std::string outputs_s = outputs.str(); + comment = cmVS10EscapeQuotes(comment); + script = cmVS10EscapeQuotes(script); + inputs_s = cmVS10EscapeQuotes(inputs_s); + outputs_s = cmVS10EscapeQuotes(outputs_s); + this->WriteCustomRuleCSharp(*i, name, script, inputs_s, outputs_s, + comment); + } else { + this->WriteCustomRuleCpp(*i, script, inputs.str(), outputs.str(), + comment); } } - this->WriteString("\n", 2); + if (this->ProjectType != csproj) { + this->WriteString("\n", 2); + } +} + +void cmVisualStudio10TargetGenerator::WriteCustomRuleCpp( + std::string const& config, std::string const& script, + std::string const& inputs, std::string const& outputs, + std::string const& comment) +{ + this->WritePlatformConfigTag("Message", config, 3); + (*this->BuildFileStream) << cmVS10EscapeXML(comment) << "\n"; + this->WritePlatformConfigTag("Command", config, 3); + (*this->BuildFileStream) << script << "\n"; + this->WritePlatformConfigTag("AdditionalInputs", config, 3); + (*this->BuildFileStream) << inputs; + (*this->BuildFileStream) << ";%(AdditionalInputs)\n"; + this->WritePlatformConfigTag("Outputs", config, 3); + (*this->BuildFileStream) << outputs << "\n"; + if (this->LocalGenerator->GetVersion() > + cmGlobalVisualStudioGenerator::VS10) { + // VS >= 11 let us turn off linking of custom command outputs. + this->WritePlatformConfigTag("LinkObjects", config, 3); + (*this->BuildFileStream) << "false\n"; + } +} + +void cmVisualStudio10TargetGenerator::WriteCustomRuleCSharp( + 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); + std::stringstream attributes; + attributes << "\n Name=\"" << name << "\""; + attributes << "\n Inputs=\"" << inputs << "\""; + attributes << "\n Outputs=\"" << outputs << "\""; + this->WritePlatformConfigTag("Target", config, 1, attributes.str().c_str(), + "\n"); + if (!comment.empty()) { + this->WriteString("BuildFileStream) << "echo " << cmVS10EscapeXML(comment) + << "\" />\n"; + } + this->WriteString("BuildFileStream) << script << "\" />\n"; + this->WriteString("\n", 1); } std::string cmVisualStudio10TargetGenerator::ConvertPath( @@ -1243,7 +1357,7 @@ void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s) } void cmVisualStudio10TargetGenerator::WriteGroups() { - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { return; } @@ -1355,7 +1469,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() std::string guidName = "SG_Filter_"; guidName += name; this->WriteString("", 3); - std::string guid = this->GlobalGenerator->GetGUID(guidName.c_str()); + std::string guid = this->GlobalGenerator->GetGUID(guidName); (*this->BuildFileStream) << "{" << guid << "}" << "\n"; this->WriteString("\n", 2); @@ -1366,7 +1480,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() this->WriteString("\n", 2); std::string guidName = "SG_Filter_Resource Files"; this->WriteString("", 3); - std::string guid = this->GlobalGenerator->GetGUID(guidName.c_str()); + std::string guid = this->GlobalGenerator->GetGUID(guidName); (*this->BuildFileStream) << "{" << guid << "}" << "\n"; this->WriteString("rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;", 3); @@ -1478,6 +1592,8 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) std::string shaderEntryPoint; std::string shaderModel; std::string shaderAdditionalFlags; + std::string outputHeaderFile; + std::string variableName; std::string settingsGenerator; std::string settingsLastGenOutput; std::string sourceLink; @@ -1485,7 +1601,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 , 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 +1614,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 { @@ -1527,6 +1643,16 @@ 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; @@ -1564,6 +1690,10 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) toolHasSettings = true; } + // Collect VS_CSHARP_* property values (if some are set) + std::map 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()); @@ -1604,7 +1734,8 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) if (!deployContent.empty()) { cmGeneratorExpression ge; - CM_AUTO_PTR cge = ge.Parse(deployContent); + std::unique_ptr cge = + ge.Parse(deployContent); // Deployment location cannot be set on a configuration basis if (!deployLocation.empty()) { this->WriteString("", 3); @@ -1647,6 +1778,28 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) (*this->BuildFileStream) << cmVS10EscapeXML(shaderModel) << "\n"; } + if (!outputHeaderFile.empty()) { + for (size_t i = 0; i != this->Configurations.size(); ++i) { + this->WriteString("BuildFileStream) << this->Configurations[i] << "|" + << this->Platform << "'\">" + << cmVS10EscapeXML(outputHeaderFile); + this->WriteString("\n", 0); + } + } + if (!variableName.empty()) { + for (size_t i = 0; i != this->Configurations.size(); ++i) { + this->WriteString("BuildFileStream) << this->Configurations[i] << "|" + << this->Platform << "'\">" + << cmVS10EscapeXML(variableName); + this->WriteString("\n", 0); + } + } if (!shaderAdditionalFlags.empty()) { this->WriteString("", 3); (*this->BuildFileStream) << cmVS10EscapeXML(shaderAdditionalFlags) @@ -1680,7 +1833,8 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf) (*this->BuildFileStream) << cmVS10EscapeXML(includeInVsix) << "\n"; } - + // write source file specific tags + this->WriteCSharpSourceProperties(sourceFileTags); this->WriteString("BuildFileStream) << tool << ">\n"; } else { @@ -1929,7 +2083,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( 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 += ";"; } @@ -1944,7 +2098,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( hasFlags = true; cmGlobalVisualStudio10Generator* gg = static_cast(this->GlobalGenerator); - cmIDEFlagTable const* flagtable = CM_NULLPTR; + cmIDEFlagTable const* flagtable = nullptr; const std::string& srclang = source->GetLanguage(); if (srclang == "C" || srclang == "CXX") { flagtable = gg->GetClFlagTable(); @@ -1970,9 +2124,9 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } if (configDependentFlags) { cmGeneratorExpression ge; - CM_AUTO_PTR cge = ge.Parse(flags); - std::string evaluatedFlags = - cge->Evaluate(this->LocalGenerator, *config); + std::unique_ptr cge = ge.Parse(flags); + std::string evaluatedFlags = cge->Evaluate( + this->LocalGenerator, *config, false, this->GeneratorTarget); clOptions.Parse(evaluatedFlags.c_str()); } else { clOptions.Parse(flags.c_str()); @@ -2002,48 +2156,23 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( std::string xamlFileName = fileName.substr(0, fileName.find_last_of(".")); (*this->BuildFileStream) << xamlFileName << "\n"; } - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { std::string f = source->GetFullPath(); typedef std::map CsPropMap; CsPropMap sourceFileTags; // set 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) << "first - << ">\n"; - } + this->WriteCSharpSourceProperties(sourceFileTags); } } @@ -2069,7 +2198,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() if (ttype > cmStateEnums::GLOBAL_TARGET) { return; } - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { return; } @@ -2081,7 +2210,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() this->Configurations.begin(); config != this->Configurations.end(); ++config) { if (ttype >= cmStateEnums::UTILITY) { - this->WritePlatformConfigTag("IntDir", config->c_str(), 2); + this->WritePlatformConfigTag("IntDir", *config, 2); *this->BuildFileStream << "$(Platform)\\$(Configuration)\\$(ProjectName)\\" << "\n"; @@ -2098,30 +2227,30 @@ 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); - this->WritePlatformConfigTag("OutDir", config->c_str(), 2); + this->WritePlatformConfigTag("OutDir", *config, 2); *this->BuildFileStream << cmVS10EscapeXML(outDir) << "\n"; - this->WritePlatformConfigTag("IntDir", config->c_str(), 2); + this->WritePlatformConfigTag("IntDir", *config, 2); *this->BuildFileStream << cmVS10EscapeXML(intermediateDir) << "\n"; if (const char* workingDir = this->GeneratorTarget->GetProperty( "VS_DEBUGGER_WORKING_DIRECTORY")) { - this->WritePlatformConfigTag("LocalDebuggerWorkingDirectory", - config->c_str(), 2); + this->WritePlatformConfigTag("LocalDebuggerWorkingDirectory", *config, + 2); *this->BuildFileStream << cmVS10EscapeXML(workingDir) << "\n"; } std::string name = cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull); - this->WritePlatformConfigTag("TargetName", config->c_str(), 2); + this->WritePlatformConfigTag("TargetName", *config, 2); *this->BuildFileStream << cmVS10EscapeXML(name) << "\n"; std::string ext = @@ -2131,7 +2260,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() // A single "." appears to be treated as an empty extension. ext = "."; } - this->WritePlatformConfigTag("TargetExt", config->c_str(), 2); + this->WritePlatformConfigTag("TargetExt", *config, 2); *this->BuildFileStream << cmVS10EscapeXML(ext) << "\n"; this->OutputLinkIncremental(*config); @@ -2146,7 +2275,7 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental( if (!this->MSTools) { return; } - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { return; } // static libraries and things greater than modules do not need @@ -2158,13 +2287,13 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental( Options& linkOptions = *(this->LinkOptions[configName]); const char* incremental = linkOptions.GetFlag("LinkIncremental"); - this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 2); + this->WritePlatformConfigTag("LinkIncremental", configName, 2); *this->BuildFileStream << (incremental ? incremental : "true") << "\n"; linkOptions.RemoveFlag("LinkIncremental"); const char* manifest = linkOptions.GetFlag("GenerateManifest"); - this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 2); + this->WritePlatformConfigTag("GenerateManifest", configName, 2); *this->BuildFileStream << (manifest ? manifest : "true") << "\n"; linkOptions.RemoveFlag("GenerateManifest"); @@ -2175,7 +2304,7 @@ 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->WritePlatformConfigTag(flag, configName, 2); *this->BuildFileStream << value << "\n"; linkOptions.RemoveFlag(flag); } @@ -2203,23 +2332,23 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( cmGlobalVisualStudio10Generator* gg = static_cast(this->GlobalGenerator); - CM_AUTO_PTR pOptions; + std::unique_ptr pOptions; switch (this->ProjectType) { case vcxproj: - pOptions = CM_AUTO_PTR(new Options( - this->LocalGenerator, Options::Compiler, gg->GetClFlagTable())); + pOptions = cm::make_unique( + this->LocalGenerator, Options::Compiler, gg->GetClFlagTable()); break; case csproj: - pOptions = CM_AUTO_PTR(new Options(this->LocalGenerator, - Options::CSharpCompiler, - gg->GetCSharpFlagTable())); + pOptions = + cm::make_unique(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: ", @@ -2250,13 +2379,13 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( baseFlagVar += "_FLAGS"; flags = this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition( - baseFlagVar.c_str()); + baseFlagVar); std::string flagVar = baseFlagVar + std::string("_") + cmSystemTools::UpperCase(configName); flags += " "; flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition( - flagVar.c_str()); + flagVar); this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, langForClCompile, configName); } @@ -2275,7 +2404,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( std::string defineFlags = this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags(); if (this->MSTools) { - if (vcxproj == this->ProjectType) { + if (this->ProjectType == vcxproj) { clOptions.FixExceptionHandlingDefault(); clOptions.AddFlag("PrecompiledHeader", "NotUsing"); std::string asmLocation = configName + "/"; @@ -2287,12 +2416,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( std::vector targetDefines; switch (this->ProjectType) { case vcxproj: - this->GeneratorTarget->GetCompileDefinitions(targetDefines, - configName.c_str(), "CXX"); + this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName, + "CXX"); break; case csproj: - this->GeneratorTarget->GetCompileDefinitions( - targetDefines, configName.c_str(), "CSharp"); + this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName, + "CSharp"); break; } clOptions.AddDefines(targetDefines); @@ -2332,7 +2461,7 @@ 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") { @@ -2340,6 +2469,12 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( clOptions.AddFlag("CallingConvention", ""); } } + if (this->ProjectType == csproj) { + // /nowin32manifest overrides /win32manifest: parameter + if (clOptions.HasFlag("NoWin32Manifest")) { + clOptions.RemoveFlag("ApplicationManifest"); + } + } this->ClOptions[configName] = pOptions.release(); return true; @@ -2371,8 +2506,7 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( } 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("" @@ -2392,8 +2526,7 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( } // 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("", 3); @@ -2422,8 +2555,8 @@ bool cmVisualStudio10TargetGenerator::ComputeRcOptions( { cmGlobalVisualStudio10Generator* gg = static_cast(this->GlobalGenerator); - CM_AUTO_PTR pOptions(new Options( - this->LocalGenerator, Options::ResourceCompiler, gg->GetRcFlagTable())); + auto pOptions = cm::make_unique( + this->LocalGenerator, Options::ResourceCompiler, gg->GetRcFlagTable()); Options& rcOptions = *pOptions; std::string CONFIG = cmSystemTools::UpperCase(configName); @@ -2483,8 +2616,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( { cmGlobalVisualStudio10Generator* gg = static_cast(this->GlobalGenerator); - CM_AUTO_PTR pOptions(new Options( - this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable())); + auto pOptions = cm::make_unique( + this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable()); Options& cudaOptions = *pOptions; // Get compile flags for CUDA in this directory. @@ -2515,6 +2648,13 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).ptx"); } + // 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 // using a secondary flag table. cudaOptions.ClearTables(); @@ -2535,8 +2675,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( cudaOptions.FixCudaCodeGeneration(); std::vector 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. @@ -2591,8 +2731,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( { cmGlobalVisualStudio10Generator* gg = static_cast(this->GlobalGenerator); - CM_AUTO_PTR pOptions(new Options( - this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable())); + auto pOptions = cm::make_unique( + this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable()); Options& cudaLinkOptions = *pOptions; // Determine if we need to do a device link @@ -2662,8 +2802,8 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions( { cmGlobalVisualStudio10Generator* gg = static_cast(this->GlobalGenerator); - CM_AUTO_PTR pOptions(new Options( - this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable())); + auto pOptions = cm::make_unique( + this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable()); Options& masmOptions = *pOptions; std::string CONFIG = cmSystemTools::UpperCase(configName); @@ -2720,8 +2860,8 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions( { cmGlobalVisualStudio10Generator* gg = static_cast(this->GlobalGenerator); - CM_AUTO_PTR pOptions(new Options( - this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable())); + auto pOptions = cm::make_unique( + this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable()); Options& nasmOptions = *pOptions; std::string CONFIG = cmSystemTools::UpperCase(configName); @@ -2882,7 +3022,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( if (const char* nativeLibDirectoriesExpression = this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES")) { cmGeneratorExpression ge; - CM_AUTO_PTR cge = + std::unique_ptr cge = ge.Parse(nativeLibDirectoriesExpression); std::string nativeLibDirs = cge->Evaluate(this->LocalGenerator, configName); @@ -2895,7 +3035,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( this->GeneratorTarget->GetProperty( "ANDROID_NATIVE_LIB_DEPENDENCIES")) { cmGeneratorExpression ge; - CM_AUTO_PTR cge = + std::unique_ptr cge = ge.Parse(nativeLibDependenciesExpression); std::string nativeLibDeps = cge->Evaluate(this->LocalGenerator, configName); @@ -2914,7 +3054,7 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions( if (const char* jarDirectoriesExpression = this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES")) { cmGeneratorExpression ge; - CM_AUTO_PTR cge = + std::unique_ptr cge = ge.Parse(jarDirectoriesExpression); std::string jarDirectories = cge->Evaluate(this->LocalGenerator, configName); @@ -2976,8 +3116,9 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( { cmGlobalVisualStudio10Generator* gg = static_cast(this->GlobalGenerator); - CM_AUTO_PTR pOptions(new Options( - this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), 0, this)); + auto pOptions = + cm::make_unique(this->LocalGenerator, Options::Linker, + gg->GetLinkFlagTable(), nullptr, this); Options& linkOptions = *pOptions; cmGeneratorTarget::LinkClosure const* linkClosure = @@ -3006,11 +3147,11 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( linkFlagVarBase += "_LINKER_FLAGS"; flags += " "; flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition( - linkFlagVarBase.c_str()); + linkFlagVarBase); std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG; flags += " "; flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition( - linkFlagVar.c_str()); + linkFlagVar); const char* targetLinkFlags = this->GeneratorTarget->GetProperty("LINK_FLAGS"); if (targetLinkFlags) { @@ -3020,13 +3161,13 @@ 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; } cmComputeLinkInformation* pcli = - this->GeneratorTarget->GetLinkInformation(config.c_str()); + this->GeneratorTarget->GetLinkInformation(config); if (!pcli) { cmSystemTools::Error( "CMake can not compute cmComputeLinkInformation for target: ", @@ -3054,8 +3195,7 @@ 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); @@ -3083,18 +3223,15 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( std::string targetNameImport; std::string targetNamePDB; if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) { - this->GeneratorTarget->GetExecutableNames(targetName, targetNameFull, - targetNameImport, targetNamePDB, - config.c_str()); + this->GeneratorTarget->GetExecutableNames( + targetName, targetNameFull, targetNameImport, targetNamePDB, config); } else { this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO, targetNameFull, targetNameImport, - targetNamePDB, config.c_str()); + targetNamePDB, config); } if (this->MSTools) { - linkOptions.AddFlag("Version", ""); - if (this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE")) { if (this->GlobalGenerator->TargetsWindowsCE()) { linkOptions.AddFlag("SubSystem", "WindowsCE"); @@ -3130,11 +3267,11 @@ 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; std::string imLib = this->GeneratorTarget->GetDirectory( - config.c_str(), cmStateEnums::ImportLibraryArtifact); + config, cmStateEnums::ImportLibraryArtifact); imLib += "/"; imLib += targetNameImport; @@ -3164,6 +3301,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions( } linkOptions.Parse(flags.c_str()); + linkOptions.FixManifestUACFlags(); if (this->MSTools) { cmGeneratorTarget::ModuleDefinitionInfo const* mdi = @@ -3209,7 +3347,7 @@ 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: ", @@ -3224,8 +3362,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions( 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()); + std::string path = + this->LocalGenerator->ConvertToRelativePath(currentBinDir, l->Value); this->ConvertToWindowsSlash(path); this->AddTargetsFileAndConfigPair(path, config); } @@ -3241,7 +3379,7 @@ void cmVisualStudio10TargetGenerator::WriteLinkOptions( this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) { return; } - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { return; } Options& linkOptions = *(this->LinkOptions[config]); @@ -3270,8 +3408,8 @@ void cmVisualStudio10TargetGenerator::AddLibraries( 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()); + std::string path = + this->LocalGenerator->ConvertToRelativePath(currentBinDir, l->Value); this->ConvertToWindowsSlash(path); if (cmVS10IsTargetsFile(l->Value)) { vsTargetVec.push_back(path); @@ -3311,7 +3449,7 @@ void cmVisualStudio10TargetGenerator::WriteMidlOptions( if (!this->MSTools) { return; } - if (csproj == this->ProjectType) { + if (this->ProjectType == csproj) { return; } @@ -3353,17 +3491,20 @@ void cmVisualStudio10TargetGenerator::WriteMidlOptions( void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups() { + if (this->ProjectType == csproj) { + return; + } for (std::vector::const_iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { std::vector includes; this->LocalGenerator->GetIncludeDirectories( - includes, this->GeneratorTarget, "C", i->c_str()); + includes, this->GeneratorTarget, "C", *i); for (std::vector::iterator ii = includes.begin(); ii != includes.end(); ++ii) { this->ConvertToWindowsSlash(*ii); } - this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1); + this->WritePlatformConfigTag("ItemDefinitionGroup", *i, 1); *this->BuildFileStream << "\n"; // output cl compile flags if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) { @@ -3377,7 +3518,7 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups() // output midl flags this->WriteMidlOptions(*i, includes); // write events - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { this->WriteEvents(*i); } // output link flags @@ -3436,24 +3577,30 @@ void cmVisualStudio10TargetGenerator::WriteEvent( for (std::vector::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)); + if (!ccg.HasOnlyEmptyCommandLines()) { + comment += pre; + comment += lg->ConstructComment(ccg); + script += pre; + pre = "\n"; + script += cmVS10EscapeXML(lg->ConstructScript(ccg)); + } } comment = cmVS10EscapeComment(comment); - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { this->WriteString("", 3); (*this->BuildFileStream) << cmVS10EscapeXML(comment) << "\n"; this->WriteString("", 3); } else { - if (!comment.empty()) { + std::string strippedComment = comment; + strippedComment.erase( + std::remove(strippedComment.begin(), strippedComment.end(), '\t'), + strippedComment.end()); + if (!comment.empty() && !strippedComment.empty()) { (*this->BuildFileStream) << "echo " << cmVS10EscapeXML(comment) << "\n"; } } (*this->BuildFileStream) << script; - if (csproj != this->ProjectType) { + if (this->ProjectType != csproj) { (*this->BuildFileStream) << ""; } (*this->BuildFileStream) << "\n"; @@ -3497,11 +3644,12 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences() this->ConvertToWindowsSlash(path); (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n"; this->WriteString("", 3); - (*this->BuildFileStream) - << "{" << this->GlobalGenerator->GetGUID(name.c_str()) << "}"; + (*this->BuildFileStream) << "{" << this->GlobalGenerator->GetGUID(name) + << "}"; (*this->BuildFileStream) << "\n"; this->WriteString("", 3); (*this->BuildFileStream) << name << "\n"; + this->WriteDotNetReferenceCustomTags(name); if (csproj == this->ProjectType) { if (!static_cast(this->GlobalGenerator) ->TargetCanBeReferenced(dt)) { @@ -3600,10 +3748,10 @@ void cmVisualStudio10TargetGenerator::WriteSDKReferences() this->WriteSingleSDKReference("WindowsIoT", iotExtensionsVersion); } } + } - if (hasWrittenItemGroup) { - this->WriteString("\n", 1); - } + if (hasWrittenItemGroup) { + this->WriteString("\n", 1); } } @@ -3777,7 +3925,7 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings() this->WriteString("true\n", 2); this->WriteString("", 2); (*this->BuildFileStream) - << cmVS10EscapeXML(this->Name.c_str()) + << cmVS10EscapeXML(this->Name) << "_$(Configuration)_$(Platform).xap\n"; } } @@ -3786,6 +3934,10 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings() this->WriteString("true" "\n", 2); + } else if (this->Platform == "ARM64") { + this->WriteString("true" + "\n", + 2); } else if (this->Platform == "ARM") { this->WriteString("true" "\n", @@ -4296,6 +4448,59 @@ bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const return true; } +void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties( + cmSourceFile const* sf, std::map& tags) +{ + if (this->ProjectType == csproj) { + 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) == 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( + const std::map& tags) +{ + if (!tags.empty()) { + for (std::map::const_iterator i = tags.begin(); + i != tags.end(); ++i) { + this->WriteString("<", 3); + (*this->BuildFileStream) << i->first << ">" << cmVS10EscapeXML(i->second) + << "first << ">\n"; + } + } +} + +void cmVisualStudio10TargetGenerator::GetCSharpSourceLink( + cmSourceFile const* sf, std::string& link) +{ + std::string f = sf->GetFullPath(); + if (!this->InSourceBuild) { + const std::string stripFromPath = + this->Makefile->GetCurrentSourceDirectory(); + if (f.find(stripFromPath) != std::string::npos) { + link = f.substr(stripFromPath.length() + 1); + if (const char* l = sf->GetProperty("VS_CSHARP_Link")) { + link = l; + } + this->ConvertToWindowsSlash(link); + } + } +} + std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath( const char* relativeFilePath) const { diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 61066158c..fb24f1ac5 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -3,7 +3,7 @@ #ifndef cmVisualStudioTargetGenerator_h #define cmVisualStudioTargetGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -66,6 +66,7 @@ private: void WriteAllSources(); void WriteDotNetReferences(); void WriteDotNetReference(std::string const& ref, std::string const& hint); + void WriteDotNetReferenceCustomTags(std::string const& ref); void WriteEmbeddedResourceGroup(); void WriteWinRTReferences(); void WriteWinRTPackageCertificateKeyFile(); @@ -126,6 +127,16 @@ private: void OutputLinkIncremental(std::string const& configName); void WriteCustomRule(cmSourceFile const* source, cmCustomCommand const& command); + void WriteCustomRuleCpp(std::string const& config, std::string const& script, + std::string const& inputs, + std::string const& outputs, + std::string const& comment); + void WriteCustomRuleCSharp(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(); void WriteCustomCommand(cmSourceFile const* sf); void WriteGroups(); @@ -153,6 +164,12 @@ private: bool ForceOld(const std::string& source) const; + void GetCSharpSourceProperties(cmSourceFile const* sf, + std::map& tags); + void WriteCSharpSourceProperties( + const std::map& tags); + void GetCSharpSourceLink(cmSourceFile const* sf, std::string& link); + private: typedef cmVisualStudioGeneratorOptions Options; typedef std::map OptionsMap; @@ -187,6 +204,7 @@ private: cmGeneratedFileStream* BuildFileStream; cmLocalVisualStudio7Generator* LocalGenerator; std::set SourcesVisited; + std::set CSharpCustomCommandNames; bool IsMissingFiles; std::vector AddedFiles; std::string DefaultArtifactDir; diff --git a/Source/cmVisualStudio10ToolsetOptions.h b/Source/cmVisualStudio10ToolsetOptions.h index 4233337ba..c736a49f5 100644 --- a/Source/cmVisualStudio10ToolsetOptions.h +++ b/Source/cmVisualStudio10ToolsetOptions.h @@ -3,7 +3,7 @@ #ifndef cmVisualStudio10ToolsetOptions_h #define cmVisualStudio10ToolsetOptions_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index 1f808c8b2..b1686bec1 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -89,7 +89,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; } } @@ -256,6 +256,74 @@ void cmVisualStudioGeneratorOptions::FixCudaCodeGeneration() } } +void cmVisualStudioGeneratorOptions::FixManifestUACFlags() +{ + static const char* ENABLE_UAC = "EnableUAC"; + if (!HasFlag(ENABLE_UAC)) { + return; + } + + const std::string uacFlag = GetFlag(ENABLE_UAC); + std::vector 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 uacMap; + uacMap["level"] = "UACExecutionLevel"; + uacMap["uiAccess"] = "UACUIAccess"; + + std::map uacExecuteLevelMap; + uacExecuteLevelMap["asInvoker"] = "AsInvoker"; + uacExecuteLevelMap["highestAvailable"] = "HighestAvailable"; + uacExecuteLevelMap["requireAdministrator"] = "RequireAdministrator"; + + for (auto const& subopt : subOptions) { + std::vector 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, keyValue[1].size() - 2)); + } + + if (keyValue[0] == "level") { + if (uacExecuteLevelMap.find(keyValue[1]) == uacExecuteLevelMap.end()) { + // unknown level value + continue; + } + + AddFlag(uacMap[keyValue[0]].c_str(), + uacExecuteLevelMap[keyValue[1]].c_str()); + continue; + } + + if (keyValue[0] == "uiAccess") { + if (keyValue[1] != "true" && keyValue[1] != "false") { + // unknown uiAccess value + continue; + } + AddFlag(uacMap[keyValue[0]].c_str(), keyValue[1].c_str()); + continue; + } + + // unknwon sub option + } + + AddFlag(ENABLE_UAC, "true"); +} + void cmVisualStudioGeneratorOptions::Parse(const char* flags) { // Parse the input string as a windows command line since the string diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h index 44d271908..7c08a2c30 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 #include @@ -77,6 +77,8 @@ public: void FixCudaCodeGeneration(); + void FixManifestUACFlags(); + bool IsDebug() const; bool IsWinRt() const; bool IsManaged() const; 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 #include diff --git a/Source/cmVisualStudioSlnParser.cxx b/Source/cmVisualStudioSlnParser.cxx index 1a32abacf..a9acb3fce 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: 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 #include 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 #include diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx index 24d7bf1bf..a08003450 100644 --- a/Source/cmWhileCommand.cxx +++ b/Source/cmWhileCommand.cxx @@ -7,9 +7,10 @@ #include "cmExpandedCommandArgument.h" #include "cmMakefile.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" +#include // IWYU pragma: keep + cmWhileFunctionBlocker::cmWhileFunctionBlocker(cmMakefile* mf) : Makefile(mf) , Depth(0) @@ -34,7 +35,8 @@ bool cmWhileFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, // 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 fb(mf.RemoveFunctionBlocker(this, lff)); + std::unique_ptr fb( + mf.RemoveFunctionBlocker(this, lff)); if (!fb.get()) { return false; } @@ -60,11 +62,10 @@ 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 += "("; @@ -78,9 +79,9 @@ bool cmWhileFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, } // 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; 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 #include @@ -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 Args; std::vector 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& args, - cmExecutionStatus&) CM_OVERRIDE; + cmExecutionStatus&) override; /** * This is called when the command is first encountered in * the CMakeLists.txt file. */ bool InitialPass(std::vector const&, - cmExecutionStatus&) CM_OVERRIDE + cmExecutionStatus&) override { return false; } 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 #include @@ -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 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 const& v, std::ostream& out, PBXType t) { bool hasOne = false; - for (std::vector::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 const& v, return; } out << "\n/* Begin " << PBXTypeNames[t] << " section */\n"; - for (std::vector::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 const&, std::ostream& out, PBXType t); static void PrintList(std::vector const&, std::ostream& out); diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx index 0def8c321..e54f1f356 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 } @@ -120,8 +120,9 @@ void cmXCodeObject::Print(std::ostream& out) out << "isa = " << PBXTypeNames[this->IsA] << ";" << separator; for (i = this->ObjectAttributes.begin(); i != this->ObjectAttributes.end(); ++i) { - if (i->first == "isa") + if (i->first == "isa") { continue; + } PrintAttribute(out, 3, separator, indentFactor, i->first, i->second, this); } @@ -129,9 +130,9 @@ void cmXCodeObject::Print(std::ostream& 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) { @@ -203,9 +204,9 @@ void cmXCodeObject::PrintList(std::vector 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); diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h index b92e6e33e..b0f1d31af 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::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*); diff --git a/Source/cmXCodeScheme.cxx b/Source/cmXCodeScheme.cxx index 5c22531d4..f1dce6420 100644 --- a/Source/cmXCodeScheme.cxx +++ b/Source/cmXCodeScheme.cxx @@ -10,13 +10,12 @@ #include "cmGeneratorTarget.h" #include "cmXMLSafe.h" -cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj, +cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj, const TestObjects& tests, const std::vector& configList, unsigned int xcVersion) : Target(xcObj) + , Tests(tests) , TargetName(xcObj->GetTarget()->GetName()) - , BuildableName(xcObj->GetTarget()->GetFullName()) - , TargetId(xcObj->GetId()) , ConfigList(configList) , XcodeVersion(xcVersion) { @@ -58,7 +57,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 +83,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 +91,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 +104,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 +126,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"); @@ -146,14 +152,7 @@ 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 @@ -164,7 +163,7 @@ void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout, } void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout, - std::string configuration) + const std::string& configuration) { xout.StartElement("ProfileAction"); xout.BreakAttributes(); @@ -177,7 +176,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 +185,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 +194,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 +222,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..e5e501a6f 100644 --- a/Source/cmXCodeScheme.h +++ b/Source/cmXCodeScheme.h @@ -5,6 +5,8 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include + #include "cmGlobalXCodeGenerator.h" #include "cmSystemTools.h" #include "cmXCodeObject.h" @@ -16,7 +18,9 @@ class cmXCodeScheme { public: - cmXCodeScheme(cmXCodeObject* xcObj, + typedef std::vector TestObjects; + + cmXCodeScheme(cmXCodeObject* xcObj, const TestObjects& tests, const std::vector& configList, unsigned int xcVersion); @@ -25,25 +29,30 @@ public: private: const cmXCodeObject* const Target; + const TestObjects Tests; const std::string& TargetName; - const std::string BuildableName; - const std::string& TargetId; const std::vector& 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); + 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..920e3a5e9 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(this->Parser), &cmXMLParserStartElement, &cmXMLParserEndElement); XML_SetCharacterDataHandler(static_cast(this->Parser), @@ -99,7 +99,7 @@ int cmXMLParser::CleanupParser() // Clean up the parser. XML_ParserFree(static_cast(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) diff --git a/Source/cmXMLWriter.h b/Source/cmXMLWriter.h index ed76a88c7..981255d41 100644 --- a/Source/cmXMLWriter.h +++ b/Source/cmXMLWriter.h @@ -3,7 +3,7 @@ #ifndef cmXMLWiter_h #define cmXMLWiter_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmXMLSafe.h" @@ -107,7 +107,7 @@ private: private: std::ostream& Output; - std::stack > Elements; + std::stack> Elements; std::string IndentationElement; std::size_t Level; bool ElementOpen; diff --git a/Source/cm_auto_ptr.hxx b/Source/cm_auto_ptr.hxx deleted file mode 100644 index 773602af9..000000000 --- a/Source/cm_auto_ptr.hxx +++ /dev/null @@ -1,220 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef CM_AUTO_PTR_HXX -#define CM_AUTO_PTR_HXX - -#include "cmConfigure.h" - -#ifdef CMake_HAVE_CXX_AUTO_PTR - -#include -#define CM_AUTO_PTR std::auto_ptr - -#else - -#define CM_AUTO_PTR cm::auto_ptr - -// The HP compiler cannot handle the conversions necessary to use -// auto_ptr_ref to pass an auto_ptr returned from one function -// directly to another function as in use_auto_ptr(get_auto_ptr()). -// We instead use const_cast to achieve the syntax on those platforms. -// We do not use const_cast on other platforms to maintain the C++ -// standard design and guarantee that if an auto_ptr is bound -// to a reference-to-const then ownership will be maintained. -#if defined(__HP_aCC) -#define cm_AUTO_PTR_REF 0 -#define cm_AUTO_PTR_CONST const -#define cm_AUTO_PTR_CAST(a) cast(a) -#else -#define cm_AUTO_PTR_REF 1 -#define cm_AUTO_PTR_CONST -#define cm_AUTO_PTR_CAST(a) a -#endif - -// In C++11, clang will warn about using dynamic exception specifications -// as they are deprecated. But as this class is trying to faithfully -// mimic std::auto_ptr, we want to keep the 'throw()' decorations below. -// So we suppress the warning. -#if defined(__clang__) && defined(__has_warning) -#if __has_warning("-Wdeprecated") -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated" -#endif -#endif - -namespace cm { - -template -class auto_ptr; - -#if cm_AUTO_PTR_REF -namespace detail { -// The auto_ptr_ref template is supposed to be a private member of -// auto_ptr but Borland 5.8 cannot handle it. Instead put it in -// a private namespace. -template -struct auto_ptr_ref -{ - Y* p_; - - // The extra constructor argument prevents implicit conversion to - // auto_ptr_ref from auto_ptr through the constructor. Normally - // this should be done with the explicit keyword but Borland 5.x - // generates code in the conversion operator to call itself - // infinately. - auto_ptr_ref(Y* p, int) - : p_(p) - { - } -}; -} -#endif - -/** C++98 Standard Section 20.4.5 - Template class auto_ptr. */ -template -class auto_ptr -{ -#if !cm_AUTO_PTR_REF - template - static inline auto_ptr& cast(auto_ptr const& a) - { - return const_cast&>(a); - } -#endif - - /** The pointer to the object held. */ - X* x_; - -public: - /** The type of object held by the auto_ptr. */ - typedef X element_type; - - /** Construct from an auto_ptr holding a compatible object. This - transfers ownership to the newly constructed auto_ptr. */ - template - auto_ptr(auto_ptr cm_AUTO_PTR_CONST& a) throw() - : x_(cm_AUTO_PTR_CAST(a).release()) - { - } - - /** Assign from an auto_ptr holding a compatible object. This - transfers ownership to the left-hand-side of the assignment. */ - template - auto_ptr& operator=(auto_ptr cm_AUTO_PTR_CONST& a) throw() // NOLINT - { - this->reset(cm_AUTO_PTR_CAST(a).release()); - return *this; // NOLINT - } - - /** - * Explicitly construct from a raw pointer. This is typically - * called with the result of operator new. For example: - * - * auto_ptr ptr(new X()); - */ - explicit auto_ptr(X* p = CM_NULLPTR) throw() - : x_(p) - { - } - - /** Construct from another auto_ptr holding an object of the same - type. This transfers ownership to the newly constructed - auto_ptr. */ - auto_ptr(auto_ptr cm_AUTO_PTR_CONST& a) throw() - : x_(cm_AUTO_PTR_CAST(a).release()) - { - } - - /** Assign from another auto_ptr holding an object of the same type. - This transfers ownership to the newly constructed auto_ptr. */ - auto_ptr& operator=(auto_ptr cm_AUTO_PTR_CONST& a) throw() // NOLINT - { - this->reset(cm_AUTO_PTR_CAST(a).release()); - return *this; // NOLINT - } - - /** Destruct and delete the object held. */ - ~auto_ptr() throw() - { - // Assume object destructor is nothrow. - delete this->x_; - } - - /** Dereference and return a reference to the object held. */ - X& operator*() const throw() { return *this->x_; } - - /** Return a pointer to the object held. */ - X* operator->() const throw() { return this->x_; } - - /** Return a pointer to the object held. */ - X* get() const throw() { return this->x_; } - - /** Return a pointer to the object held and reset to hold no object. - This transfers ownership to the caller. */ - X* release() throw() - { - X* x = this->x_; - this->x_ = CM_NULLPTR; - return x; - } - - /** Assume ownership of the given object. The object previously - held is deleted. */ - void reset(X* p = 0) throw() - { - if (this->x_ != p) { - // Assume object destructor is nothrow. - delete this->x_; - this->x_ = p; - } - } - - /** Convert to an auto_ptr holding an object of a compatible type. - This transfers ownership to the returned auto_ptr. */ - template - operator auto_ptr() throw() - { - return auto_ptr(this->release()); - } - -#if cm_AUTO_PTR_REF - /** Construct from an auto_ptr_ref. This is used when the - constructor argument is a call to a function returning an - auto_ptr. */ - auto_ptr(detail::auto_ptr_ref r) throw() - : x_(r.p_) - { - } - - /** Assign from an auto_ptr_ref. This is used when a function - returning an auto_ptr is passed on the right-hand-side of an - assignment. */ - auto_ptr& operator=(detail::auto_ptr_ref r) throw() - { - this->reset(r.p_); - return *this; // NOLINT - } - - /** Convert to an auto_ptr_ref. This is used when a function - returning an auto_ptr is the argument to the constructor of - another auto_ptr. */ - template - operator detail::auto_ptr_ref() throw() - { - return detail::auto_ptr_ref(this->release(), 1); - } -#endif -}; - -} // namespace cm - -// Undo warning suppression. -#if defined(__clang__) && defined(__has_warning) -#if __has_warning("-Wdeprecated") -#pragma clang diagnostic pop -#endif -#endif - -#endif - -#endif diff --git a/Source/cm_codecvt.hxx b/Source/cm_codecvt.hxx index 30c6d5407..3a5606b3d 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 #include @@ -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 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 // include sys/stat.h after sys/types.h #include diff --git a/Source/cm_unordered_map.hxx b/Source/cm_unordered_map.hxx deleted file mode 100644 index bf3890314..000000000 --- a/Source/cm_unordered_map.hxx +++ /dev/null @@ -1,25 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef CM_UNORDERED_MAP_HXX -#define CM_UNORDERED_MAP_HXX - -#include "cmConfigure.h" - -#if defined(CMake_HAVE_CXX_UNORDERED_MAP) - -#include -#define CM_UNORDERED_MAP std::unordered_map - -#elif defined(CMAKE_BUILD_WITH_CMAKE) - -#include "cmsys/hash_map.hxx" -#define CM_UNORDERED_MAP cmsys::hash_map - -#else - -#include -#define CM_UNORDERED_MAP std::map - -#endif - -#endif diff --git a/Source/cm_unordered_set.hxx b/Source/cm_unordered_set.hxx deleted file mode 100644 index dd1a9a115..000000000 --- a/Source/cm_unordered_set.hxx +++ /dev/null @@ -1,25 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef CM_UNORDERED_SET_HXX -#define CM_UNORDERED_SET_HXX - -#include "cmConfigure.h" - -#if defined(CMake_HAVE_CXX_UNORDERED_SET) - -#include -#define CM_UNORDERED_SET std::unordered_set - -#elif defined(CMAKE_BUILD_WITH_CMAKE) - -#include "cmsys/hash_set.hxx" -#define CM_UNORDERED_SET cmsys::hash_set - -#else - -#include -#define CM_UNORDERED_SET std::set - -#endif - -#endif diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 689439378..fd7151f08 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -24,7 +24,6 @@ #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) @@ -32,7 +31,7 @@ #include "cmGraphVizWriter.h" #include "cmVariableWatch.h" -#include "cm_unordered_map.hxx" +#include #endif // only build kdevelop generator on non-windows platforms @@ -111,6 +110,7 @@ #include "cmsys/RegularExpression.hxx" #include #include +#include // IWYU pragma: keep #include #include #include @@ -120,7 +120,7 @@ namespace { #if defined(CMAKE_BUILD_WITH_CMAKE) -typedef CM_UNORDERED_MAP JsonValueMapType; +typedef std::unordered_map JsonValueMapType; #endif } // namespace @@ -163,9 +163,9 @@ cmake::cmake(Role role) } #endif - this->GlobalGenerator = CM_NULLPTR; - this->ProgressCallback = CM_NULLPTR; - this->ProgressCallbackClientData = CM_NULLPTR; + this->GlobalGenerator = nullptr; + this->ProgressCallback = nullptr; + this->ProgressCallbackClientData = nullptr; this->CurrentWorkingMode = NORMAL_MODE; #ifdef CMAKE_BUILD_WITH_CMAKE @@ -215,7 +215,7 @@ 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 @@ -244,31 +244,28 @@ Json::Value cmake::ReportCapabilitiesJson(bool haveServerMode) const this->GetRegisteredGenerators(generatorInfoList); JsonValueMapType generatorMap; - for (std::vector::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; @@ -407,21 +404,18 @@ bool cmake::SetCacheArgs(const std::vector& args) // removed std::vector entriesToDelete; std::vector cacheKeys = this->State->GetCacheEntryKeys(); - for (std::vector::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.c_str())) { + entriesToDelete.push_back(ck); } } } // now remove them from the cache - for (std::vector::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); @@ -488,15 +482,15 @@ void cmake::ReadListFile(const std::vector& args, snapshot.GetDirectory().SetCurrentSource( cmSystemTools::GetCurrentWorkingDirectory()); snapshot.SetDefaultDefinitions(); - CM_AUTO_PTR 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.c_str()); - mf->SetArgcArgv(args); + mf.SetArgcArgv(args); } - if (!mf->ReadListFile(path)) { + if (!mf.ReadListFile(path)) { cmSystemTools::Error("Error processing file: ", path); } this->SetHomeDirectory(homeDir); @@ -555,7 +549,7 @@ bool cmake::FindPackage(const std::vector& 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 +562,8 @@ bool cmake::FindPackage(const std::vector& args) std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES"); std::vector libList; cmSystemTools::ExpandListArgument(libs, libList); - for (std::vector::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"); @@ -906,49 +899,42 @@ void cmake::AddDefaultExtraGenerators() void cmake::GetRegisteredGenerators( std::vector& generators) const { - for (RegisteredGeneratorsVector::const_iterator i = this->Generators.begin(), - e = this->Generators.end(); - i != e; ++i) { + for (cmGlobalGeneratorFactory* gen : this->Generators) { std::vector names; - (*i)->GetGenerators(names); + gen->GetGenerators(names); - 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.name = name; + info.baseName = name; info.isAlias = false; generators.push_back(info); } } - for (RegisteredExtraGeneratorsVector::const_iterator - i = this->ExtraGenerators.begin(), - e = this->ExtraGenerators.end(); - i != e; ++i) { + for (cmExternalMakefileProjectGeneratorFactory* eg : this->ExtraGenerators) { const std::vector genList = - (*i)->GetSupportedGlobalGenerators(); - for (std::vector::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); } - for (std::vector::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; @@ -962,28 +948,24 @@ createExtraGenerator( const std::vector& in, const std::string& name) { - for (std::vector::const_iterator - i = in.begin(); - i != in.end(); ++i) { + for (cmExternalMakefileProjectGeneratorFactory* i : in) { const std::vector 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::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(CM_NULLPTR), name); + static_cast(nullptr), name); } cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname) @@ -993,10 +975,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; } @@ -1091,10 +1072,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(); } } @@ -1192,9 +1173,8 @@ int cmake::HandleDeleteCacheVariables(const std::string& var) // load the empty cache this->LoadCache(); // restore the changed compilers - for (std::vector::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()); // avoid reconfigure if there were errors @@ -1348,9 +1328,8 @@ int cmake::ActualConfigure() if (const char* platformName = this->State->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM")) { - if (this->GeneratorPlatform.empty()) { - this->GeneratorPlatform = platformName; - } else if (this->GeneratorPlatform != platformName) { + if (!this->GeneratorPlatform.empty() && + this->GeneratorPlatform != platformName) { std::string message = "Error: generator platform: "; message += this->GeneratorPlatform; message += "\nDoes not match the platform used previously: "; @@ -1368,9 +1347,7 @@ int cmake::ActualConfigure() if (const char* tsName = this->State->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET")) { - if (this->GeneratorToolset.empty()) { - this->GeneratorToolset = tsName; - } else if (this->GeneratorToolset != tsName) { + if (!this->GeneratorToolset.empty() && this->GeneratorToolset != tsName) { std::string message = "Error: generator toolset: "; message += this->GeneratorToolset; message += "\nDoes not match the toolset used previously: "; @@ -1791,35 +1768,30 @@ void cmake::SetIsInTryCompile(bool b) void cmake::GetGeneratorDocumentation(std::vector& v) { - for (RegisteredGeneratorsVector::const_iterator i = this->Generators.begin(); - i != this->Generators.end(); ++i) { + for (cmGlobalGeneratorFactory* g : this->Generators) { cmDocumentationEntry e; - (*i)->GetDocumentation(e); + g->GetDocumentation(e); v.push_back(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(); + for (cmExternalMakefileProjectGeneratorFactory* eg : this->ExtraGenerators) { + const std::string doc = eg->GetDocumentation(); + const std::string name = eg->GetName(); // Aliases: - for (std::vector::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); } // Full names: const std::vector generators = - (*i)->GetSupportedGlobalGenerators(); - for (std::vector::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); } @@ -1899,8 +1871,8 @@ int cmake::CheckBuildSystem() cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); - if (!mf->ReadListFile(this->CheckBuildSystemArgument.c_str()) || + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); + if (!mf.ReadListFile(this->CheckBuildSystemArgument.c_str()) || cmSystemTools::GetErrorOccuredFlag()) { if (verbose) { std::ostringstream msg; @@ -1914,34 +1886,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 ggd(this->CreateGlobalGenerator(genName)); - if (ggd.get()) { + std::unique_ptr ggd( + this->CreateGlobalGenerator(genName)); + if (ggd) { cm.GetCurrentSnapshot().SetDefaultDefinitions(); - CM_AUTO_PTR mfd( - new cmMakefile(ggd.get(), cm.GetCurrentSnapshot())); - CM_AUTO_PTR lgd(ggd->CreateLocalGenerator(mfd.get())); - lgd->ClearDependencies(mfd.get(), verbose); + cmMakefile mfd(ggd.get(), cm.GetCurrentSnapshot()); + std::unique_ptr lgd(ggd->CreateLocalGenerator(&mfd)); + lgd->ClearDependencies(&mfd, verbose); } } // If any byproduct of makefile generation is missing we must re-run. std::vector 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::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.c_str()) || + cmSystemTools::FileIsSymlink(p))) { if (verbose) { std::ostringstream msg; - msg << "Re-run cmake, missing byproduct: " << *pi << "\n"; + msg << "Re-run cmake, missing byproduct: " << p << "\n"; cmSystemTools::Stdout(msg.str().c_str()); } return 1; @@ -1951,8 +1922,8 @@ int cmake::CheckBuildSystem() // Get the set of dependencies and outputs. std::vector depends; std::vector 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); @@ -2065,19 +2036,18 @@ void cmake::MarkCliAsUsed(const std::string& variable) void cmake::GenerateGraphViz(const char* fileName) const { #ifdef CMAKE_BUILD_WITH_CMAKE - CM_AUTO_PTR gvWriter( - new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators())); + cmGraphVizWriter gvWriter(this->GetGlobalGenerator()->GetLocalGenerators()); std::string settingsFile = this->GetHomeOutputDirectory(); settingsFile += "/CMakeGraphVizOptions.cmake"; std::string fallbackSettingsFile = this->GetHomeDirectory(); fallbackSettingsFile += "/CMakeGraphVizOptions.cmake"; - gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str()); + gvWriter.ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str()); - gvWriter->WritePerTargetFiles(fileName); - gvWriter->WriteTargetDependersFiles(fileName); - gvWriter->WriteGlobalFile(fileName); + gvWriter.WritePerTargetFiles(fileName); + gvWriter.WriteTargetDependersFiles(fileName); + gvWriter.WriteGlobalFile(fileName); #endif } @@ -2127,7 +2097,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& args) @@ -2383,7 +2353,7 @@ 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 gen( + std::unique_ptr gen( this->CreateGlobalGenerator(cachedGenerator)); if (!gen.get()) { std::cerr << "Error: could create CMAKE_GENERATOR \"" << cachedGenerator @@ -2479,12 +2449,10 @@ void cmake::RunCheckForUnusedVariables() bool haveUnused = false; std::ostringstream msg; msg << "Manually-specified variables were not used by the project:"; - for (std::map::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) { diff --git a/Source/cmake.h b/Source/cmake.h index 4ddacf701..b31b6f5ce 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -3,7 +3,7 @@ #ifndef cmake_h #define cmake_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include #include @@ -209,24 +209,12 @@ public: this->GeneratorPlatform = ts; } - ///! Get the name of the selected generator-specific platform. - std::string const& GetGeneratorPlatform() const - { - return this->GeneratorPlatform; - } - ///! Set the name of the selected generator-specific toolset. void SetGeneratorToolset(std::string const& ts) { this->GeneratorToolset = ts; } - ///! Get the name of the selected generator-specific toolset. - std::string const& GetGeneratorToolset() const - { - return this->GeneratorToolset; - } - const std::vector& GetSourceExtensions() const { return this->SourceFileExtensions; @@ -268,8 +256,7 @@ 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, void* clientData = nullptr); ///! this is called by generators to update the progress void UpdateProgress(const char* msg, float prog); diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index da1fe6d64..a1dfc3e89 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.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 "cmake.h" #include "cmAlgorithms.h" #include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" @@ -9,7 +9,6 @@ #include "cmState.h" #include "cmStateTypes.h" #include "cmSystemTools.h" -#include "cmake.h" #include "cmcmd.h" #ifdef CMAKE_BUILD_WITH_CMAKE @@ -17,6 +16,12 @@ #include "cmDynamicLoader.h" #endif +#ifdef _WIN32 +#include /* _O_TEXT */ +#include /* _set_fmode, _fmode */ +#endif +#include "cm_uv.h" + #include "cmsys/Encoding.hxx" #if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) #include "cmsys/ConsoleBuf.hxx" @@ -26,33 +31,24 @@ #include #include -#ifdef CMAKE_USE_LIBUV -#ifdef _WIN32 -#include /* _O_TEXT */ -#include /* _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] \n" - " cmake [options] " }, - { CM_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, " cmake [options] \n" + " cmake [options] " }, + { 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." }, + { 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 \ @@ -88,7 +84,7 @@ static const char* cmDocumentationOptions[][2] = { { "--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 } + { nullptr, nullptr } }; #endif @@ -107,14 +103,14 @@ static int do_build(int ac, char const* const* av); static cmMakefile* cmakemainGetMakefile(void* clientdata) { - cmake* cm = (cmake*)clientdata; + cmake* cm = static_cast(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) @@ -172,7 +168,7 @@ int main(int ac, char const* const* av) ac = args.argc(); av = args.argv(); -#if defined(CMAKE_USE_LIBUV) && defined(_WIN32) +#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. @@ -198,9 +194,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; } @@ -310,30 +304,28 @@ int do_cmake(int ac, char const* const* av) cmake cm(role); cm.SetHomeDirectory(""); cm.SetHomeOutputDirectory(""); - cmSystemTools::SetMessageCallback(cmakemainMessageCallback, (void*)&cm); - cm.SetProgressCallback(cmakemainProgressCallback, (void*)&cm); + cmSystemTools::SetMessageCallback(cmakemainMessageCallback, &cm); + cm.SetProgressCallback(cmakemainProgressCallback, &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 keys = cm.GetState()->GetCacheEntryKeys(); - for (std::vector::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; } @@ -381,7 +373,7 @@ static int do_build(int ac, char const* const* av) hasTarget = true; } else { std::cerr << "'--target' may not be specified more than once.\n\n"; - dir = ""; + dir.clear(); break; } } else if (strcmp(av[i], "--config") == 0) { @@ -409,7 +401,7 @@ static int do_build(int ac, char const* const* av) break; default: std::cerr << "Unknown argument " << av[i] << std::endl; - dir = ""; + dir.clear(); break; } } @@ -426,8 +418,8 @@ static int do_build(int ac, char const* const* av) } cmake cm(cmake::RoleInternal); - cmSystemTools::SetMessageCallback(cmakemainMessageCallback, (void*)&cm); - cm.SetProgressCallback(cmakemainProgressCallback, (void*)&cm); + cmSystemTools::SetMessageCallback(cmakemainMessageCallback, &cm); + cm.SetProgressCallback(cmakemainProgressCallback, &cm); return cm.Build(dir, target, config, nativeOptions, clean); #endif } diff --git a/Source/cmakexbuild.cxx b/Source/cmakexbuild.cxx index 72da456d4..20ead4785 100644 --- a/Source/cmakexbuild.cxx +++ b/Source/cmakexbuild.cxx @@ -47,7 +47,7 @@ int RunXCode(std::vector& argv, bool& hitbug) } pipe = cmSystemTools::WaitForLine(cp, line, 100, out, err); } - cmsysProcess_WaitForExit(cp, 0); + cmsysProcess_WaitForExit(cp, nullptr); if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exited) { return cmsysProcess_GetExitValue(cp); } @@ -64,7 +64,7 @@ int main(int ac, char* av[]) for (int i = 1; i < ac; i++) { argv.push_back(av[i]); } - argv.push_back(0); + argv.push_back(nullptr); bool hitbug = true; int ret = 0; while (hitbug) { diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index d5b086174..69339b448 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -12,16 +12,12 @@ #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 "cmServer.h" +#include "cmServerConnection.h" #endif #if defined(CMAKE_BUILD_WITH_CMAKE) && defined(_WIN32) @@ -32,18 +28,21 @@ #include "cmVisualStudioWCEPlatformParser.h" #endif -#include "cmConfigure.h" #include "cmsys/Directory.hxx" #include "cmsys/FStream.hxx" #include "cmsys/Process.h" #include "cmsys/Terminal.h" #include #include +#include // IWYU pragma: keep #include #include #include +#include #include +class cmConnection; + int cmcmd_cmake_ninja_depends(std::vector::const_iterator argBeg, std::vector::const_iterator argEnd); int cmcmd_cmake_ninja_dyndep(std::vector::const_iterator argBeg, @@ -88,6 +87,11 @@ void CMakeCommandUsage(const char* program) << " environment - display the current environment\n" << " make_directory ... - create parent and directories\n" << " md5sum ... - create MD5 checksum of files\n" + << " sha1sum ... - create SHA1 checksum of files\n" + << " sha224sum ... - create SHA224 checksum of files\n" + << " sha256sum ... - create SHA256 checksum of files\n" + << " sha384sum ... - create SHA384 checksum of files\n" + << " sha512sum ... - create SHA512 checksum of files\n" << " remove [-f] ... - remove the file(s), use -f to force " "it\n" << " remove_directory dir - remove a directory and its contents\n" @@ -154,6 +158,291 @@ static bool cmTarFilesFrom(std::string const& file, return true; } +static int HandleIWYU(const std::string& runCmd, + const std::string& /* sourceFile */, + const std::vector& orig_cmd) +{ + // Construct the iwyu command line by taking what was given + // and adding all the arguments we give to the compiler. + std::vector iwyu_cmd; + cmSystemTools::ExpandListArgument(runCmd, 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; + 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& 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 tidy_cmd; + cmSystemTools::ExpandListArgument(runCmd, 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, + 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&) +{ + // Construct the ldd -r -u (link what you use lwyu) command line + // ldd -u -r lwuy target + std::vector lwyu_cmd; + lwyu_cmd.push_back("ldd"); + lwyu_cmd.push_back("-u"); + lwyu_cmd.push_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&) +{ + // Construct the cpplint command line. + std::vector 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; + } + + // Output the output from cpplint to stderr + std::cerr << stdOut; + return ret; +} + +static int HandleCppCheck(const std::string& runCmd, + const std::string& sourceFile, + const std::vector& orig_cmd) +{ + // Construct the cpplint command line. + std::vector 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) { + std::cerr << "Warning: cppcheck reported diagnostics:\n"; + } + std::cerr << stdErr; + // ignore errors so build continues + return 0; +} + +typedef int (*CoCompileHandler)(const std::string&, const std::string&, + const std::vector&); + +struct CoCompiler +{ + const char* Option; + CoCompileHandler Handler; + bool NoOriginalCommand; +}; + +static CoCompiler 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& args) +{ + std::vector jobs; + std::string sourceFile; // store --source= + + // 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 orig_cmd; + bool doing_options = true; + for (std::string::size_type i = 2; i < args.size(); ++i) { + std::string const& arg = args[i]; + // 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 = cmArrayBegin(CoCompilers); + cc != cmArrayEnd(CoCompilers); ++cc) { + 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 (cmHasLiteralPrefix(arg, "--source=")) { + sourceFile = arg.substr(9); + optionFound = true; + } + // if it was not a co-compiler or --source then error + if (!optionFound) { + 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 = cmArrayBegin(CoCompilers); + cc != cmArrayEnd(CoCompilers); ++cc) { + 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; + } + + // 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& args) { // IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx @@ -277,181 +566,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector& 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 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 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 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 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 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 @@ -497,8 +613,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) // Execute command from remaining arguments. std::vector 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; } @@ -584,7 +700,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) return 1; } cmake cm(cmake::RoleInternal); -#if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE +#if defined(CMAKE_BUILD_WITH_CMAKE) std::cout << cm.ReportCapabilities(true); #else std::cout << cm.ReportCapabilities(false); @@ -623,7 +739,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& 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,24 +757,28 @@ int cmcmd::ExecuteCMakeCommand(std::vector& 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. @@ -675,8 +795,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) 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.c_str(), nullptr, nullptr, &retval, directory.c_str(), + cmSystemTools::OUTPUT_PASSTHROUGH, timeout)) { return retval; } @@ -820,8 +940,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) cmStateSnapshot snapshot = cm.GetCurrentSnapshot(); snapshot.GetDirectory().SetCurrentBinary(startOutDir); snapshot.GetDirectory().SetCurrentSource(startDir); - CM_AUTO_PTR mf(new cmMakefile(ggd, snapshot)); - CM_AUTO_PTR lgd(ggd->CreateLocalGenerator(mf.get())); + cmMakefile mf(ggd, snapshot); + std::unique_ptr lgd(ggd->CreateLocalGenerator(&mf)); // Actually scan dependencies. return lgd->UpdateDependencies(depInfo.c_str(), verbose, color) ? 0 @@ -1012,8 +1132,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector& 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 { @@ -1074,6 +1194,33 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) return 1; } +int cmcmd::HashSumFile(std::vector& args, cmCryptoHash::Algo algo) +{ + if (args.size() < 3) { + return -1; + } + int retval = 0; + + for (std::string::size_type cc = 2; cc < args.size(); cc++) { + const char* filename = args[cc].c_str(); + // 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& args) { int result = 0; @@ -1277,7 +1424,7 @@ int cmcmd::ExecuteLinkScript(std::vector& 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 +1434,7 @@ int cmcmd::ExecuteLinkScript(std::vector& 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)) { @@ -1375,24 +1522,23 @@ 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& args, int type) +int cmcmd::VisualStudioLink(std::vector const& args, int type) { if (args.size() < 2) { return -1; } const bool verbose = cmSystemTools::HasEnv("VERBOSE"); std::vector expandedArgs; - for (std::vector::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 +1549,38 @@ int cmcmd::VisualStudioLink(std::vector& args, int type) return vsLink.Link(); } +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& command, - bool verbose, int* retCodeOut = CM_NULLPTR) + bool verbose, NumberFormat exitFormat, + int* retCodeOut = nullptr, + bool (*retCodeOkay)(int) = nullptr) { if (verbose) { std::cout << comment << ":\n"; @@ -1412,32 +1588,32 @@ static bool RunCommand(const char* comment, std::vector& 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::const_iterator argBeg, @@ -1535,6 +1711,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: @@ -1587,10 +1770,10 @@ int cmVSLink::LinkIncremental() // Compile the resource file. std::vector rcCommand; - rcCommand.push_back(cmSystemTools::FindProgram("rc.exe")); + rcCommand.push_back("rc"); rcCommand.push_back("/fo" + 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 +1781,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 +1811,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,7 +1829,7 @@ int cmVSLink::LinkNonIncremental() int cmVSLink::RunMT(std::string const& out, bool notify) { std::vector mtCommand; - mtCommand.push_back(cmSystemTools::FindProgram("mt.exe")); + mtCommand.push_back("mt"); mtCommand.push_back("/nologo"); mtCommand.push_back("/manifest"); if (this->LinkGeneratesManifest) { @@ -1659,7 +1844,8 @@ int cmVSLink::RunMT(std::string const& out, bool notify) mtCommand.push_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..d1e03d01f 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 #include @@ -18,6 +19,9 @@ public: static int ExecuteCMakeCommand(std::vector&); protected: + static int HandleCoCompileCommands(std::vector& args); + static int HashSumFile(std::vector& args, + cmCryptoHash::Algo algo); static int SymlinkLibrary(std::vector& args); static int SymlinkExecutable(std::vector& args); static bool SymlinkInternal(std::string const& file, @@ -26,7 +30,7 @@ protected: static int ExecuteLinkScript(std::vector& args); static int WindowsCEEnvironment(const char* version, const std::string& name); - static int VisualStudioLink(std::vector& args, int type); + static int VisualStudioLink(std::vector const& args, int type); }; #endif diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 84e815d1d..f6466fad7 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" @@ -18,13 +17,13 @@ #include 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 , --build-config ", "Choose configuration to test." }, @@ -83,6 +82,8 @@ static const char* cmDocumentationOptions[][2] = { { "--max-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." }, @@ -118,7 +119,7 @@ static const char* cmDocumentationOptions[][2] = { { "--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. @@ -185,6 +186,7 @@ int main(int argc, char const* const* argv) // copy the args to a vector std::vector args; + args.reserve(argc); for (int i = 0; i < argc; ++i) { args.push_back(argv[i]); } diff --git a/Source/kwsys/.gitattributes b/Source/kwsys/.gitattributes deleted file mode 100644 index 7065eb5cb..000000000 --- a/Source/kwsys/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ -.git* export-ignore - -*.c kwsys-c-style -*.c.in kwsys-c-style -*.cxx kwsys-c-style -*.h kwsys-c-style -*.h.in kwsys-c-style -*.hxx kwsys-c-style -*.hxx.in kwsys-c-style - -*.cmake whitespace=tab-in-indent -*.rst whitespace=tab-in-indent conflict-marker-size=79 -*.txt whitespace=tab-in-indent diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index e915b1a80..21568bbed 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -20,6 +20,21 @@ # 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. # # Example: # @@ -79,6 +94,10 @@ FOREACH(p ENDFOREACH() SET(CMAKE_LEGACY_CYGWIN_WIN32 0) +IF(CMAKE_VERSION VERSION_LESS 3.0) + SET(KWSYS_SPLIT_OBJECTS_FROM_INTERFACE 0) +ENDIF() + #----------------------------------------------------------------------------- # If a namespace is not specified, use "kwsys" and enable testing. # This should be the case only when kwsys is not included inside @@ -430,6 +449,11 @@ SET_SOURCE_FILES_PROPERTIES(ProcessUNIX.c System.c PROPERTIES COMPILE_FLAGS "-DKWSYS_C_HAS_PTRDIFF_T=${KWSYS_C_HAS_PTRDIFF_T} -DKWSYS_C_HAS_SSIZE_T=${KWSYS_C_HAS_SSIZE_T}" ) +IF(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) @@ -795,68 +819,144 @@ 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) + 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 + $) + 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}) + 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) 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 + $) + IF(KWSYS_INSTALL_INCLUDE_DIR) + TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_INTERFACE} INTERFACE + $) + 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() 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) + 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 + $) + 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 + $) + IF(KWSYS_INSTALL_INCLUDE_DIR) + TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_C_INTERFACE} INTERFACE + $) + 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() @@ -915,7 +1015,7 @@ 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) + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsC ${KWSYS_TARGET_C_LINK}) FOREACH(test ${KWSYS_C_TESTS}) ADD_TEST(kwsys.${test} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsC ${test} ${KWSYS_TEST_ARGS_${test}}) SET_PROPERTY(TEST kwsys.${test} PROPERTY LABELS ${KWSYS_LABELS_TEST}) @@ -928,10 +1028,10 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) ) ENDIF() SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} - testIOS testSystemTools testCommandLineArguments testCommandLineArguments1 + testDirectory ) IF(KWSYS_STL_HAS_WSTRING) SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} @@ -950,7 +1050,7 @@ 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 ) @@ -969,7 +1069,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) # 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}) ENDIF() CREATE_TEST_SOURCELIST( KWSYS_CXX_TEST_SRCS ${KWSYS_NAMESPACE}TestsCxx.cxx @@ -981,7 +1081,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}") @@ -1032,7 +1132,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() @@ -1060,7 +1160,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/Directory.cxx b/Source/kwsys/Directory.cxx index 5141d4519..69068aaf8 100644 --- a/Source/kwsys/Directory.cxx +++ b/Source/kwsys/Directory.cxx @@ -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) { diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index 9ebcfce59..3b32ca7d0 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -99,7 +99,8 @@ 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__) +#if !defined(__BEOS__) && !defined(__VMS) && !defined(__MINT__) && \ + !defined(KWSYSPE_USE_SELECT) #define KWSYSPE_USE_SELECT 1 #endif diff --git a/Source/kwsys/RegularExpression.cxx b/Source/kwsys/RegularExpression.cxx index 6d7f83295..26e84e04e 100644 --- a/Source/kwsys/RegularExpression.cxx +++ b/Source/kwsys/RegularExpression.cxx @@ -258,11 +258,6 @@ const unsigned char MAGIC = 0234; #define UCHARAT(p) (reinterpret_cast(p))[0] -#define FAIL(m) \ - { \ - regerror(m); \ - return (0); \ - } #define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?') #define META "^$.[()|?+*\\" diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 1c4fe3389..ecfa3319b 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -22,7 +22,6 @@ #include KWSYS_HEADER(FStream.hxx) #include KWSYS_HEADER(Encoding.hxx) -#include #include #include #include @@ -848,6 +847,8 @@ void SystemTools::ReplaceString(std::string& source, const char* replace, free(orig); } +#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 @@ -856,7 +857,6 @@ void SystemTools::ReplaceString(std::string& source, const char* replace, #define KWSYS_ST_KEY_WOW64_64KEY 0x0100 #endif -#if defined(_WIN32) && !defined(__CYGWIN__) static bool SystemToolsParseRegistryKey(const std::string& key, HKEY& primaryKey, std::string& second, std::string& valuename) @@ -2269,11 +2269,7 @@ 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 size_t fileNum; if (!SystemTools::MakeDirectory(destination)) { return false; @@ -2375,104 +2371,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((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((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; @@ -2626,11 +2524,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(fileNum)), ".") && @@ -3709,16 +3603,6 @@ std::string SystemTools::JoinPath( return result; } -void SystemTools::RemoveEmptyPathElements(std::vector& 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__) @@ -3807,11 +3691,7 @@ 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("/\\"); -#else - std::string::size_type slash_pos = filename.rfind('/'); -#endif if (slash_pos != std::string::npos) { return filename.substr(slash_pos + 1); } else { @@ -4124,66 +4004,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 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]; diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index 5e091c2af..35bc1b19b 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -205,13 +205,6 @@ public: */ 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 @@ -461,6 +454,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& components, @@ -469,15 +466,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& components); static std::string JoinPath(std::vector::const_iterator first, std::vector::const_iterator last); - /** Removes empty components from path. - */ - static void RemoveEmptyPathElements(std::vector& path); - /** * Compare a path or components of a path. */ @@ -493,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) */ diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx index 01c69514c..e67d43662 100644 --- a/Source/kwsys/kwsysPlatformTestsCXX.cxx +++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx @@ -265,6 +265,12 @@ int main() #ifdef TEST_KWSYS_CXX_HAS_UTIMENSAT #include #include +#if defined(__APPLE__) +#include +#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 } }; diff --git a/Source/kwsys/testDirectory.cxx b/Source/kwsys/testDirectory.cxx new file mode 100644 index 000000000..983f2c631 --- /dev/null +++ b/Source/kwsys/testDirectory.cxx @@ -0,0 +1,79 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying +file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ +#include "kwsysPrivate.h" +#include KWSYS_HEADER(Directory.hxx) +#include KWSYS_HEADER(Encoding.hxx) +#include KWSYS_HEADER(SystemTools.hxx) + +// 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 "SystemTools.hxx.in" +#endif + +#include +#include +#include + +#include + +int _doLongPathTest() +{ + using namespace kwsys; + static const int LONG_PATH_THRESHOLD = 512; + int res = 0; + std::string topdir(TEST_SYSTEMTOOLS_BINARY_DIR "/directory_testing/"); + std::stringstream testpathstrm; + std::string testdirpath; + std::string extendedtestdirpath; + + testpathstrm << topdir; + size_t pathlen = testpathstrm.str().length(); + testpathstrm.seekp(0, std::ios_base::end); + while (pathlen < LONG_PATH_THRESHOLD) { + testpathstrm << "0123456789/"; + pathlen = testpathstrm.str().length(); + } + + testdirpath = testpathstrm.str(); +#ifdef _WIN32 + extendedtestdirpath = + Encoding::ToNarrow(SystemTools::ConvertToWindowsExtendedPath(testdirpath)); +#else + extendedtestdirpath = testdirpath; +#endif + + if (SystemTools::MakeDirectory(extendedtestdirpath)) { + std::ofstream testfile1( + (extendedtestdirpath + "longfilepathtest1.txt").c_str()); + std::ofstream testfile2( + (extendedtestdirpath + "longfilepathtest2.txt").c_str()); + testfile1 << "foo"; + testfile2 << "bar"; + testfile1.close(); + testfile2.close(); + + Directory testdir; + // Set res to failure if the directory doesn't load + res += !testdir.Load(testdirpath); + // Increment res failure if the directory appears empty + res += testdir.GetNumberOfFiles() == 0; + // Increment res failures if the path has changed from + // what was provided. + res += testdirpath != testdir.GetPath(); + + SystemTools::RemoveADirectory(topdir); + } else { + std::cerr << "Failed to create directory with long path: " + << extendedtestdirpath << std::endl; + res += 1; + } + return res; +} + +int testDirectory(int, char* []) +{ + return _doLongPathTest(); +} diff --git a/Source/kwsys/testIOS.cxx b/Source/kwsys/testIOS.cxx deleted file mode 100644 index 3e4c325c7..000000000 --- a/Source/kwsys/testIOS.cxx +++ /dev/null @@ -1,139 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -#include "kwsysPrivate.h" -#include KWSYS_HEADER(Configure.hxx) - -#include -#include -#include -#include /* strlen */ -#include - -// Work-around CMake dependency scanning limitation. This must -// duplicate the above list of headers. -#if 0 -#include "Configure.hxx.in" -#endif - -int testIOS(int, char* []) -{ - std::ostringstream ostr; - const char hello[] = "hello"; - ostr << hello; - if (ostr.str() != hello) { - std::cerr << "failed to write hello to ostr" << std::endl; - return 1; - } - const char world[] = "world"; - std::ostringstream ostr2; - ostr2.write(hello, strlen(hello)); /* I could do sizeof */ - ostr2.put('\0'); - ostr2.write(world, strlen(world)); - if (ostr2.str().size() != strlen(hello) + 1 + strlen(world)) { - std::cerr << "failed to write hello to ostr2" << std::endl; - return 1; - } - static const unsigned char array[] = { - 0xff, 0x4f, 0xff, 0x51, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, - 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x01, 0xff, 0x52, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x04, 0x04, 0x00, 0x01, 0xff, - 0x5c, 0x00, 0x13, 0x40, 0x40, 0x48, 0x48, 0x50, 0x48, 0x48, 0x50, 0x48, - 0x48, 0x50, 0x48, 0x48, 0x50, 0x48, 0x48, 0x50, 0xff, 0x64, 0x00, 0x2c, - 0x00, 0x00, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, - 0x20, 0x49, 0x54, 0x4b, 0x2f, 0x47, 0x44, 0x43, 0x4d, 0x2f, 0x4f, 0x70, - 0x65, 0x6e, 0x4a, 0x50, 0x45, 0x47, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x20, 0x31, 0x2e, 0x30, 0xff, 0x90, 0x00, 0x0a, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x2c, 0x00, 0x01, 0xff, 0x93, 0xcf, 0xb0, 0x18, 0x08, - 0x7f, 0xc6, 0x99, 0xbf, 0xff, 0xc0, 0xf8, 0xc1, 0xc1, 0xf3, 0x05, 0x81, - 0xf2, 0x83, 0x0a, 0xa5, 0xff, 0x10, 0x90, 0xbf, 0x2f, 0xff, 0x04, 0xa8, - 0x7f, 0xc0, 0xf8, 0xc4, 0xc1, 0xf3, 0x09, 0x81, 0xf3, 0x0c, 0x19, 0x34 - }; - const size_t narray = sizeof(array); // 180 - std::stringstream strstr; - strstr.write((char*)array, narray); - // strstr.seekp( narray / 2 ); // set position of put pointer in mid string - if (strstr.str().size() != narray) { - std::cerr << "failed to write array to strstr" << std::endl; - return 1; - } - - std::istringstream istr(" 10 20 str "); - std::string s; - int x; - if (istr >> x) { - if (x != 10) { - std::cerr << "x != 10" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read 10 from istr" << std::endl; - return 1; - } - if (istr >> x) { - if (x != 20) { - std::cerr << "x != 20" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read 20 from istr" << std::endl; - return 1; - } - if (istr >> s) { - if (s != "str") { - std::cerr << "s != \"str\"" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read str from istr" << std::endl; - return 1; - } - if (istr >> s) { - std::cerr << "Able to read past end of stream" << std::endl; - return 1; - } else { - // Clear the failure. - istr.clear(istr.rdstate() & ~std::ios::eofbit); - istr.clear(istr.rdstate() & ~std::ios::failbit); - } - istr.str("30"); - if (istr >> x) { - if (x != 30) { - std::cerr << "x != 30" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read 30 from istr" << std::endl; - return 1; - } - - std::stringstream sstr; - sstr << "40 str2"; - if (sstr >> x) { - if (x != 40) { - std::cerr << "x != 40" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read 40 from sstr" << std::endl; - return 1; - } - if (sstr >> s) { - if (s != "str2") { - std::cerr << "s != \"str2\"" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read str2 from sstr" << std::endl; - return 1; - } - - // Just try to compile this. - if (x == 12345) { - std::ifstream fin("/does_not_exist", std::ios::in | std::ios::binary); - } - - std::cout << "IOS tests passed" << std::endl; - return 0; -} diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx index e6fbf6cda..768eb4d12 100644 --- a/Source/kwsys/testSystemTools.cxx +++ b/Source/kwsys/testSystemTools.cxx @@ -22,6 +22,7 @@ #include #include +#include /* free */ #include /* strcmp */ #if defined(_WIN32) && !defined(__CYGWIN__) #include /* _umask (MSVC) / umask (Borland) */ @@ -535,15 +536,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 ")) { @@ -758,6 +758,30 @@ static bool CheckGetPath() return res; } +static bool CheckGetFilenameName() +{ + const char* windowsFilepath = "C:\\somewhere\\something"; + const char* unixFilepath = "/somewhere/something"; + + std::string expectedFilename = "something"; + + bool res = true; + std::string filename = kwsys::SystemTools::GetFilenameName(windowsFilepath); + if (filename != expectedFilename) { + std::cerr << "GetFilenameName(" << windowsFilepath << ") yielded " + << filename << " instead of " << expectedFilename << std::endl; + res = false; + } + + filename = kwsys::SystemTools::GetFilenameName(unixFilepath); + if (filename != expectedFilename) { + std::cerr << "GetFilenameName(" << unixFilepath << ") yielded " << filename + << " instead of " << expectedFilename << std::endl; + res = false; + } + return res; +} + static bool CheckFind() { bool res = true; @@ -875,5 +899,7 @@ int testSystemTools(int, char* []) res &= CheckGetLineFromStream(); + res &= CheckGetFilenameName(); + return res ? 0 : 1; } -- cgit v1.2.3