diff options
author | Orkun Tokdemir <ilhanorkuntokdemir@gmail.com> | 2023-05-12 14:09:38 (GMT) |
---|---|---|
committer | Orkun Tokdemir <ilhanorkuntokdemir@gmail.com> | 2023-05-12 14:09:38 (GMT) |
commit | 023af4ab2f8d45d0ed5ca6acdf3018cd4cee4624 (patch) | |
tree | 44431e403ecc628c23ffd196aa4353b3be201bc2 | |
parent | c568a6bcf2b50599bb03f433dd0e95916791a965 (diff) | |
download | CMake-023af4ab2f8d45d0ed5ca6acdf3018cd4cee4624.zip CMake-023af4ab2f8d45d0ed5ca6acdf3018cd4cee4624.tar.gz CMake-023af4ab2f8d45d0ed5ca6acdf3018cd4cee4624.tar.bz2 |
Improve Const Correctness
-rw-r--r-- | Source/cmMakefileTargetGenerator.cxx | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 02cdf57..cf09d09 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -420,7 +420,7 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules() this->GeneratorTarget->HasLinkDependencyFile(this->GetConfigName()); if (compilerGenerateDeps || linkerGenerateDeps || ccGenerateDeps) { - std::string compilerDependFile = + std::string const compilerDependFile = cmStrCat(this->TargetBuildDirectoryFull, "/compiler_depend.make"); *this->BuildFileStream << "# Include any dependencies generated by the " "compiler for this target.\n" @@ -613,17 +613,17 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( } // Use compiler to generate dependencies, if supported. - bool compilerGenerateDeps = + bool const compilerGenerateDeps = this->GlobalGenerator->SupportsCompilerDependencies() && cmIsOn(this->Makefile->GetDefinition( cmStrCat("CMAKE_", lang, "_DEPENDS_USE_COMPILER"))); - auto scanner = compilerGenerateDeps ? cmDependencyScannerKind::Compiler - : cmDependencyScannerKind::CMake; + auto const scanner = compilerGenerateDeps ? cmDependencyScannerKind::Compiler + : cmDependencyScannerKind::CMake; // Get the full path name of the object file. std::string const& objectName = this->GeneratorTarget->GetObjectName(&source); - std::string obj = + std::string const obj = cmStrCat(this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), '/', objectName); @@ -642,7 +642,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( // Create the directory containing the object file. This may be a // subdirectory under the target's directory. { - std::string dir = cmSystemTools::GetFilenamePath(obj); + std::string const dir = cmSystemTools::GetFilenamePath(obj); cmSystemTools::MakeDirectory(this->LocalGenerator->ConvertToFullPath(dir)); } @@ -656,7 +656,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( std::string objFullPath = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/', obj); objFullPath = cmSystemTools::CollapseFullPath(objFullPath); - std::string srcFullPath = + std::string const srcFullPath = cmSystemTools::CollapseFullPath(source.GetFullPath()); this->LocalGenerator->AddImplicitDepends(this->GeneratorTarget, lang, objFullPath, srcFullPath, scanner); @@ -669,8 +669,8 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( // generate the depend scanning rule this->WriteObjectDependRules(source, depends); - std::string config = this->GetConfigName(); - std::string configUpper = cmSystemTools::UpperCase(config); + std::string const config = this->GetConfigName(); + std::string const configUpper = cmSystemTools::UpperCase(config); // Add precompile headers dependencies std::vector<std::string> architectures = @@ -726,7 +726,8 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( this->GeneratorTarget->AddExplicitLanguageFlags(flags, source); // Add language-specific flags. - std::string langFlags = cmStrCat("$(", lang, "_FLAGS", filterArch, ")"); + std::string const langFlags = + cmStrCat("$(", lang, "_FLAGS", filterArch, ")"); this->LocalGenerator->AppendFlags(flags, langFlags); cmGeneratorExpressionInterpreter genexInterpreter( @@ -745,7 +746,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( cmSystemTools::GetFilenameWithoutLastExtension(objectName); ispcSource = cmSystemTools::GetFilenameWithoutLastExtension(ispcSource); - cmValue ispcSuffixProp = + cmValue const ispcSuffixProp = this->GeneratorTarget->GetProperty("ISPC_HEADER_SUFFIX"); assert(ispcSuffixProp); @@ -784,7 +785,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( // Add precompile headers compile options. if (!pchSources.empty() && !source.GetProperty("SKIP_PRECOMPILE_HEADERS")) { std::string pchOptions; - auto pchIt = pchSources.find(source.GetFullPath()); + auto const pchIt = pchSources.find(source.GetFullPath()); if (pchIt != pchSources.end()) { pchOptions = this->GeneratorTarget->GetPchCreateCompileOptions( config, lang, pchIt->second); @@ -830,7 +831,8 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( << "_DEFINES = " << evaluatedDefs << "\n" << "\n"; } - std::string defPropName = cmStrCat("COMPILE_DEFINITIONS_", configUpper); + std::string const defPropName = + cmStrCat("COMPILE_DEFINITIONS_", configUpper); if (cmValue config_compile_defs = source.GetProperty(defPropName)) { const std::string& evaluatedDefs = genexInterpreter.Evaluate(*config_compile_defs, COMPILE_DEFINITIONS); @@ -841,7 +843,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( } // Get the output paths for source and object files. - std::string sourceFile = this->LocalGenerator->ConvertToOutputFormat( + std::string const sourceFile = this->LocalGenerator->ConvertToOutputFormat( source.GetFullPath(), cmOutputConverter::SHELL); // Construct the build message. @@ -897,7 +899,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( targetOutPathCompilePDB.back() = '/'; } - std::string compilePdbOutputPath = + std::string const compilePdbOutputPath = this->GeneratorTarget->GetCompilePDBDirectory(this->GetConfigName()); cmSystemTools::MakeDirectory(compilePdbOutputPath); } @@ -910,7 +912,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( vars.TargetPDB = targetOutPathPDB.c_str(); vars.TargetCompilePDB = targetOutPathCompilePDB.c_str(); vars.Source = sourceFile.c_str(); - std::string shellObj = + std::string const shellObj = this->LocalGenerator->ConvertToOutputFormat(obj, cmOutputConverter::SHELL); vars.Object = shellObj.c_str(); std::string objectDir = this->GeneratorTarget->GetSupportDirectory(); @@ -960,7 +962,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( // At the moment, it is assumed that C, C++, Fortran, and CUDA have both // assembly and preprocessor capabilities. The same is true for the // ability to export compile commands - bool lang_has_preprocessor = + bool const lang_has_preprocessor = ((lang == "C") || (lang == "CXX") || (lang == "OBJC") || (lang == "OBJCXX") || (lang == "Fortran") || (lang == "CUDA") || lang == "ISPC" || lang == "HIP" || lang == "ASM"); @@ -1016,31 +1018,31 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( // no launcher for CMAKE_EXPORT_COMPILE_COMMANDS rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, compileCommand, vars); - std::string workingDirectory = + std::string const workingDirectory = this->LocalGenerator->GetCurrentBinaryDirectory(); std::string::size_type lfPos = compileCommand.find(langFlags); if (lfPos != std::string::npos) { compileCommand.replace(lfPos, langFlags.size(), this->GetFlags(lang, this->GetConfigName())); } - std::string langDefines = std::string("$(") + lang + "_DEFINES)"; - std::string::size_type ldPos = compileCommand.find(langDefines); + std::string const langDefines = std::string("$(") + lang + "_DEFINES)"; + std::string::size_type const ldPos = compileCommand.find(langDefines); if (ldPos != std::string::npos) { compileCommand.replace(ldPos, langDefines.size(), this->GetDefines(lang, this->GetConfigName())); } - std::string langIncludes = std::string("$(") + lang + "_INCLUDES)"; - std::string::size_type liPos = compileCommand.find(langIncludes); + std::string const langIncludes = std::string("$(") + lang + "_INCLUDES)"; + std::string::size_type const liPos = compileCommand.find(langIncludes); if (liPos != std::string::npos) { compileCommand.replace(liPos, langIncludes.size(), this->GetIncludes(lang, this->GetConfigName())); } - cmValue eliminate[] = { + cmValue const eliminate[] = { this->Makefile->GetDefinition("CMAKE_START_TEMP_FILE"), this->Makefile->GetDefinition("CMAKE_END_TEMP_FILE") }; - for (cmValue el : eliminate) { + for (cmValue const& el : eliminate) { if (el) { cmSystemTools::ReplaceString(compileCommand, *el, ""); } @@ -1330,8 +1332,8 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles( if (do_preprocess_rules) { commands.clear(); - std::string relativeObjI = relativeObjBase + ".i"; - std::string objI = objBase + ".i"; + std::string const relativeObjI = relativeObjBase + ".i"; + std::string const objI = objBase + ".i"; std::string preprocessEcho = cmStrCat("Preprocessing ", lang, " source to ", objI); @@ -1423,7 +1425,7 @@ void cmMakefileTargetGenerator::WriteTargetCleanRules() std::vector<std::string> commands; // Construct the clean target name. - std::string cleanTarget = cmStrCat( + std::string const cleanTarget = cmStrCat( this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget), "/clean"); @@ -1451,7 +1453,7 @@ bool cmMakefileTargetGenerator::WriteMakeRule( } // Check whether we need to bother checking for a symbolic output. - bool need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark(); + bool const need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark(); // Check whether the first output is marked as symbolic. if (need_symbolic) { @@ -1481,7 +1483,7 @@ bool cmMakefileTargetGenerator::WriteMakeRule( bool o_symbolic = false; if (need_symbolic) { - if (cmSourceFile* sf = this->Makefile->GetSource(output)) { + if (cmSourceFile const* sf = this->Makefile->GetSource(output)) { o_symbolic = sf->GetPropertyAsBool("SYMBOLIC"); } } @@ -1559,7 +1561,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() "# Targets to which this target links which contain Fortran sources.\n" "set(CMAKE_Fortran_TARGET_LINKED_INFO_FILES\n"; /* clang-format on */ - std::vector<std::string> dirs = + std::vector<std::string> const dirs = this->GetLinkedTargetDirectories("Fortran", this->GetConfigName()); for (std::string const& d : dirs) { *this->InfoFileStream << " \"" << d << "/DependInfo.cmake\"\n"; @@ -1591,7 +1593,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() std::vector<std::string> commands; // Construct the name of the dependency generation target. - std::string depTarget = cmStrCat( + std::string const depTarget = cmStrCat( this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget), "/depend"); @@ -1701,7 +1703,7 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule( deps.emplace_back(cmStrCat(relPath, obj)); } - std::unordered_set<std::string> depsSet(deps.begin(), deps.end()); + std::unordered_set<std::string> const depsSet(deps.begin(), deps.end()); deps.clear(); std::copy(depsSet.begin(), depsSet.end(), std::back_inserter(deps)); return deps; @@ -1785,7 +1787,7 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule( this->GetDeviceLinkFlags(linkFlags, "CUDA"); vars.LinkFlags = linkFlags.c_str(); - std::string flags = this->GetFlags("CUDA", this->GetConfigName()); + std::string const flags = this->GetFlags("CUDA", this->GetConfigName()); vars.Flags = flags.c_str(); std::string compileCmd = this->GetLinkRule("CMAKE_CUDA_DEVICE_LINK_COMPILE"); @@ -1839,8 +1841,8 @@ void cmMakefileTargetGenerator::GenerateCustomRuleFile( // Write the rule. const std::vector<std::string>& outputs = ccg.GetOutputs(); - bool symbolic = this->WriteMakeRule(*this->BuildFileStream, nullptr, outputs, - depends, commands); + bool const symbolic = this->WriteMakeRule(*this->BuildFileStream, nullptr, + outputs, depends, commands); // Symbolic inputs are not expected to exist, so add dummy rules. if (this->CMP0113New && !depends.empty()) { @@ -2328,7 +2330,7 @@ void cmMakefileTargetGenerator::CreateObjectLists( useWatcomQuote); if (useResponseFile) { // MSVC response files cannot exceed 128K. - std::string::size_type const responseFileLimit = 131000; + std::string::size_type constexpr responseFileLimit = 131000; // Construct the individual object list strings. std::vector<std::string> object_strings; @@ -2461,7 +2463,8 @@ std::string cmMakefileTargetGenerator::GetResponseFlag( std::string responseFlag = "@"; std::string responseFlagVar; - auto lang = this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName()); + auto const lang = + this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName()); if (mode == cmMakefileTargetGenerator::ResponseFlagFor::Link) { responseFlagVar = cmStrCat("CMAKE_", lang, "_RESPONSE_FILE_LINK_FLAG"); } else if (mode == cmMakefileTargetGenerator::ResponseFlagFor::DeviceLink) { |