Improve Const Correctness

This commit is contained in:
Orkun Tokdemir 2023-05-12 16:09:38 +02:00
parent c568a6bcf2
commit 023af4ab2f

View File

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