1
0
Эх сурвалжийг харах

Merge topic 'refactor-ostream-usage'

c225897ca0 cmExportCMakeConfigGenerator: Optimize `std::ostream::operator<<` calls
bdece1c754 Refactor: Optimize `ostream::operator<<()` calls for some generators

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !10079
Brad King 10 сар өмнө
parent
commit
f4428d9784

+ 39 - 47
Source/cmExportCMakeConfigGenerator.cxx

@@ -93,8 +93,8 @@ void cmExportCMakeConfigGenerator::GenerateInterfaceProperties(
       cmStrCat(this->Namespace, target->GetExportName());
     os << "set_target_properties(" << targetName << " PROPERTIES\n";
     for (auto const& property : properties) {
-      os << "  " << property.first << " "
-         << cmExportFileGeneratorEscape(property.second) << "\n";
+      os << "  " << property.first << ' '
+         << cmExportFileGeneratorEscape(property.second) << '\n';
     }
     os << ")\n\n";
   }
@@ -164,22 +164,22 @@ void cmExportCMakeConfigGenerator::GeneratePolicyHeaderCode(std::ostream& os)
 {
   // Protect that file against use with older CMake versions.
   /* clang-format off */
-  os << "# Generated by CMake\n\n";
-  os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.8)\n"
-     << "   message(FATAL_ERROR \"CMake >= "
+  os << "# Generated by CMake\n\n"
+        "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.8)\n"
+        "   message(FATAL_ERROR \"CMake >= "
      << this->RequiredCMakeVersionMajor << '.'
      << this->RequiredCMakeVersionMinor << '.'
      << this->RequiredCMakeVersionPatch << " required\")\n"
-     << "endif()\n"
-     << "if(CMAKE_VERSION VERSION_LESS \""
+        "endif()\n"
+        "if(CMAKE_VERSION VERSION_LESS \""
      << this->RequiredCMakeVersionMajor << '.'
      << this->RequiredCMakeVersionMinor << '.'
      << this->RequiredCMakeVersionPatch << "\")\n"
-     << "   message(FATAL_ERROR \"CMake >= "
+        "   message(FATAL_ERROR \"CMake >= "
      << this->RequiredCMakeVersionMajor << '.'
      << this->RequiredCMakeVersionMinor << '.'
      << this->RequiredCMakeVersionPatch << " required\")\n"
-     << "endif()\n";
+        "endif()\n";
   /* clang-format on */
 
   // Isolate the file policy level.
@@ -191,7 +191,7 @@ void cmExportCMakeConfigGenerator::GeneratePolicyHeaderCode(std::ostream& os)
   // versions.
   /* clang-format off */
   os << "cmake_policy(PUSH)\n"
-     << "cmake_policy(VERSION "
+        "cmake_policy(VERSION "
      << this->RequiredCMakeVersionMajor << '.'
      << this->RequiredCMakeVersionMinor << '.'
      << this->RequiredCMakeVersionPatch << "...3.30)\n";
@@ -207,32 +207,30 @@ void cmExportCMakeConfigGenerator::GenerateImportHeaderCode(
   std::ostream& os, std::string const& config)
 {
   os << "#----------------------------------------------------------------\n"
-     << "# Generated CMake target import file";
+        "# Generated CMake target import file";
   if (!config.empty()) {
     os << " for configuration \"" << config << "\".\n";
   } else {
     os << ".\n";
   }
   os << "#----------------------------------------------------------------\n"
-     << "\n";
+        "\n";
   this->GenerateImportVersionCode(os);
 }
 
 void cmExportCMakeConfigGenerator::GenerateImportFooterCode(std::ostream& os)
 {
   os << "# Commands beyond this point should not need to know the version.\n"
-     << "set(CMAKE_IMPORT_FILE_VERSION)\n";
+        "set(CMAKE_IMPORT_FILE_VERSION)\n";
 }
 
 void cmExportCMakeConfigGenerator::GenerateImportVersionCode(std::ostream& os)
 {
   // Store an import file format version.  This will let us change the
   // format later while still allowing old import files to work.
-  /* clang-format off */
   os << "# Commands may need to know the format version.\n"
-     << "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
-     << "\n";
-  /* clang-format on */
+        "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
+        "\n";
 }
 
 void cmExportCMakeConfigGenerator::GenerateExpectedTargetsCode(
@@ -355,7 +353,7 @@ void cmExportCMakeConfigGenerator::GenerateImportTargetCode(
     os << "set_property(TARGET " << targetName << " PROPERTY SYSTEM 0)\n";
   }
 
-  os << "\n";
+  os << '\n';
 }
 
 void cmExportCMakeConfigGenerator::GenerateImportPropertyCode(
@@ -370,22 +368,24 @@ void cmExportCMakeConfigGenerator::GenerateImportPropertyCode(
 
   // Set the import properties.
   os << "# Import target \"" << targetName << "\" for configuration \""
-     << config << "\"\n";
-  os << "set_property(TARGET " << targetName
-     << " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
+     << config
+     << "\"\n"
+        "set_property(TARGET "
+     << targetName << " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
   if (!config.empty()) {
     os << cmSystemTools::UpperCase(config);
   } else {
     os << "NOCONFIG";
   }
-  os << ")\n";
-  os << "set_target_properties(" << targetName << " PROPERTIES\n";
+  os << ")\n"
+        "set_target_properties("
+     << targetName << " PROPERTIES\n";
   std::string importedLocationProp = cmStrCat("IMPORTED_LOCATION", suffix);
   for (auto const& property : properties) {
     if (importedXcFrameworkLocation.empty() ||
         property.first != importedLocationProp) {
-      os << "  " << property.first << " "
-         << cmExportFileGeneratorEscape(property.second) << "\n";
+      os << "  " << property.first << ' '
+         << cmExportFileGeneratorEscape(property.second) << '\n';
     }
   }
   os << "  )\n";
@@ -396,15 +396,15 @@ void cmExportCMakeConfigGenerator::GenerateImportPropertyCode(
          << cmExportFileGeneratorEscape(importedXcFrameworkLocation)
          << ")\n"
             "  set_property(TARGET "
-         << targetName << " PROPERTY " << importedLocationProp << " "
+         << targetName << " PROPERTY " << importedLocationProp << ' '
          << cmExportFileGeneratorEscape(importedXcFrameworkLocation)
          << ")\nelse()\n  set_property(TARGET " << targetName << " PROPERTY "
-         << importedLocationProp << " "
+         << importedLocationProp << ' '
          << cmExportFileGeneratorEscape(importedLocationIt->second)
          << ")\nendif()\n";
     }
   }
-  os << "\n";
+  os << '\n';
 }
 
 void cmExportCMakeConfigGenerator::GenerateFindDependencyCalls(
@@ -467,7 +467,7 @@ void cmExportCMakeConfigGenerator::GenerateFindDependencyCalls(
     if (it.second.Enabled == cmExportSet::PackageDependencyExportEnabled::On) {
       os << "find_dependency(" << it.first;
       for (auto const& arg : it.second.ExtraArguments) {
-        os << " " << cmOutputConverter::EscapeForCMake(arg);
+        os << ' ' << cmOutputConverter::EscapeForCMake(arg);
       }
       os << ")\n";
     }
@@ -479,26 +479,21 @@ void cmExportCMakeConfigGenerator::GenerateMissingTargetsCheckCode(
   std::ostream& os)
 {
   if (this->MissingTargets.empty()) {
-    /* clang-format off */
     os << "# This file does not depend on other imported targets which have\n"
           "# been exported from the same project but in a separate "
-            "export set.\n\n";
-    /* clang-format on */
+          "export set.\n\n";
     return;
   }
-  /* clang-format off */
   os << "# Make sure the targets which have been exported in some other\n"
         "# export set exist.\n"
         "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
         "foreach(_target ";
-  /* clang-format on */
   std::set<std::string> emitted;
   for (std::string const& missingTarget : this->MissingTargets) {
     if (emitted.insert(missingTarget).second) {
-      os << "\"" << missingTarget << "\" ";
+      os << '"' << missingTarget << "\" ";
     }
   }
-  /* clang-format off */
   os << ")\n"
         "  if(NOT TARGET \"${_target}\" )\n"
         "    set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets \""
@@ -513,16 +508,15 @@ void cmExportCMakeConfigGenerator::GenerateMissingTargetsCheckCode(
         "    set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "
         "\"The following imported targets are "
         "referenced, but are missing: "
-                 "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
+        "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
         "  else()\n"
         "    message(FATAL_ERROR \"The following imported targets are "
         "referenced, but are missing: "
-                "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
+        "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
         "  endif()\n"
         "endif()\n"
         "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
         "\n";
-  /* clang-format on */
 }
 
 void cmExportCMakeConfigGenerator::GenerateImportedFileCheckLoop(
@@ -535,7 +529,6 @@ void cmExportCMakeConfigGenerator::GenerateImportedFileCheckLoop(
   // the non-development package, something similar happened to me without
   // on SUSE with a mysql pkg-config file, which claimed everything is fine,
   // but the development package was not installed.).
-  /* clang-format off */
   os << "# Loop over all imported files and verify that they actually exist\n"
         "foreach(_cmake_target IN LISTS _cmake_import_check_targets)\n"
         "  if(CMAKE_VERSION VERSION_LESS \"3.28\"\n"
@@ -565,7 +558,6 @@ void cmExportCMakeConfigGenerator::GenerateImportedFileCheckLoop(
         "unset(_cmake_target)\n"
         "unset(_cmake_import_check_targets)\n"
         "\n";
-  /* clang-format on */
 }
 
 void cmExportCMakeConfigGenerator::GenerateImportedFileChecksCode(
@@ -582,12 +574,12 @@ void cmExportCMakeConfigGenerator::GenerateImportedFileChecksCode(
     os << "set(_cmake_import_check_xcframework_for_" << targetName << ' '
        << cmExportFileGeneratorEscape(importedXcFrameworkLocation) << ")\n";
   }
-  os << "list(APPEND _cmake_import_check_files_for_" << targetName << " ";
+  os << "list(APPEND _cmake_import_check_files_for_" << targetName << ' ';
 
   for (std::string const& li : importedLocations) {
     auto pi = properties.find(li);
     if (pi != properties.end()) {
-      os << cmExportFileGeneratorEscape(pi->second) << " ";
+      os << cmExportFileGeneratorEscape(pi->second) << ' ';
     }
   }
 
@@ -602,7 +594,7 @@ void cmExportCMakeConfigGenerator::GenerateTargetFileSets(
     std::string targetName = cmStrCat(this->Namespace, gte->GetExportName());
     os << "if(NOT CMAKE_VERSION VERSION_LESS \"3.23.0\")\n"
           "  target_sources("
-       << targetName << "\n";
+       << targetName << '\n';
 
     for (auto const& name : interfaceFileSets) {
       auto* fileSet = gte->Target->GetFileSet(name);
@@ -621,7 +613,7 @@ void cmExportCMakeConfigGenerator::GenerateTargetFileSets(
          << cmOutputConverter::EscapeForCMake(fileSet->GetType())
          << "\n      BASE_DIRS "
          << this->GetFileSetDirectories(gte, fileSet, te) << "\n      FILES "
-         << this->GetFileSetFiles(gte, fileSet, te) << "\n";
+         << this->GetFileSetFiles(gte, fileSet, te) << '\n';
     }
 
     os << "  )\nelse()\n  set_property(TARGET " << targetName
@@ -667,8 +659,8 @@ void cmExportCMakeConfigGenerator::GenerateCxxModuleInformation(
 
   // Write the include.
   os << "# Include C++ module properties\n"
-     << "include(\"${CMAKE_CURRENT_LIST_DIR}/" << cxx_module_dirname
-     << "/cxx-modules-" << name << ".cmake\")\n\n";
+        "include(\"${CMAKE_CURRENT_LIST_DIR}/"
+     << cxx_module_dirname << "/cxx-modules-" << name << ".cmake\")\n\n";
 
   // Include all configuration-specific include files.
   cmGeneratedFileStream ap(this->GetCxxModuleFile(name), true);

+ 9 - 20
Source/cmGlobalGenerator.cxx

@@ -468,8 +468,9 @@ bool cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
   if (mf->GetDefinition("CMAKE_MAKE_PROGRAM").IsOff()) {
     std::ostringstream err;
     err << "CMake was unable to find a build program corresponding to \""
-        << this->GetName() << "\".  CMAKE_MAKE_PROGRAM is not set.  You "
-        << "probably need to select a different build tool.";
+        << this->GetName()
+        << "\".  CMAKE_MAKE_PROGRAM is not set.  You "
+           "probably need to select a different build tool.";
     cmSystemTools::Error(err.str());
     cmSystemTools::SetFatalErrorOccurred();
     return false;
@@ -872,11 +873,7 @@ void cmGlobalGenerator::EnableLanguage(
     std::ostringstream noCompiler;
     cmValue compilerFile = mf->GetDefinition(compilerName);
     if (!cmNonempty(compilerFile) || cmIsNOTFOUND(*compilerFile)) {
-      /* clang-format off */
-      noCompiler <<
-        "No " << compilerName << " could be found.\n"
-        ;
-      /* clang-format on */
+      noCompiler << "No " << compilerName << " could be found.\n";
     } else if ((lang != "RC") && (lang != "ASM_MARMASM") &&
                (lang != "ASM_MASM")) {
       if (!cmSystemTools::FileIsFullPath(*compilerFile)) {
@@ -2368,32 +2365,24 @@ std::string cmGlobalGenerator::GenerateCMakeBuildCommand(
   makeCommand =
     cmStrCat(cmSystemTools::ConvertToOutputPath(makeCommand), " --build .");
   if (!config.empty()) {
-    makeCommand += " --config \"";
-    makeCommand += config;
-    makeCommand += "\"";
+    makeCommand = cmStrCat(makeCommand, " --config \"", config, '"');
   }
   if (!parallel.empty()) {
-    makeCommand += " --parallel \"";
-    makeCommand += parallel;
-    makeCommand += "\"";
+    makeCommand = cmStrCat(makeCommand, " --parallel \"", parallel, '"');
   }
   if (!target.empty()) {
-    makeCommand += " --target \"";
-    makeCommand += target;
-    makeCommand += "\"";
+    makeCommand = cmStrCat(makeCommand, " --target \"", target, '"');
   }
   const char* sep = " -- ";
   if (ignoreErrors) {
     const char* iflag = this->GetBuildIgnoreErrorsFlag();
     if (iflag && *iflag) {
-      makeCommand += sep;
-      makeCommand += iflag;
+      makeCommand = cmStrCat(makeCommand, sep, iflag);
       sep = " ";
     }
   }
   if (!native.empty()) {
-    makeCommand += sep;
-    makeCommand += native;
+    makeCommand = cmStrCat(makeCommand, sep, native);
   }
   return makeCommand;
 }

+ 8 - 6
Source/cmLocalNinjaGenerator.cxx

@@ -283,8 +283,10 @@ void cmLocalNinjaGenerator::WriteBuildFileTop()
 void cmLocalNinjaGenerator::WriteProjectHeader(std::ostream& os)
 {
   cmGlobalNinjaGenerator::WriteDivider(os);
-  os << "# Project: " << this->GetProjectName() << '\n'
-     << "# Configurations: " << cmJoin(this->GetConfigNames(), ", ") << '\n';
+  os << "# Project: " << this->GetProjectName()
+     << "\n"
+        "# Configurations: "
+     << cmJoin(this->GetConfigNames(), ", ") << '\n';
   cmGlobalNinjaGenerator::WriteDivider(os);
 }
 
@@ -360,7 +362,7 @@ void cmLocalNinjaGenerator::WriteNinjaFilesInclusionConfig(std::ostream& os)
   std::string const commonFilePath = ng->EncodePath(ninjaCommonFile);
   cmGlobalNinjaGenerator::WriteInclude(os, commonFilePath,
                                        "Include common file.");
-  os << "\n";
+  os << '\n';
 }
 
 void cmLocalNinjaGenerator::WriteNinjaFilesInclusionCommon(std::ostream& os)
@@ -373,7 +375,7 @@ void cmLocalNinjaGenerator::WriteNinjaFilesInclusionCommon(std::ostream& os)
   std::string const rulesFilePath = ng->EncodePath(ninjaRulesFile);
   cmGlobalNinjaGenerator::WriteInclude(os, rulesFilePath,
                                        "Include rules file.");
-  os << "\n";
+  os << '\n';
 }
 
 void cmLocalNinjaGenerator::WriteNinjaWorkDir(std::ostream& os)
@@ -391,8 +393,8 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
 {
   cmGlobalNinjaGenerator::WriteDivider(os);
   os << "# Write statements declared in CMakeLists.txt:\n"
-     << "# " << this->Makefile->GetSafeDefinition("CMAKE_CURRENT_LIST_FILE")
-     << '\n';
+        "# "
+     << this->Makefile->GetSafeDefinition("CMAKE_CURRENT_LIST_FILE") << '\n';
   if (this->IsRootMakefile()) {
     os << "# Which is the root file.\n";
   }

+ 101 - 128
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -480,42 +480,36 @@ void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
   this->WriteDisclaimer(infoFileStream);
 
   // Setup relative path conversion tops.
-  /* clang-format off */
-  infoFileStream
-    << "# Relative path conversion top directories.\n"
-    << "set(CMAKE_RELATIVE_PATH_TOP_SOURCE \""
-    << this->GetRelativePathTopSource() << "\")\n"
-    << "set(CMAKE_RELATIVE_PATH_TOP_BINARY \""
-    << this->GetRelativePathTopBinary() << "\")\n"
-    << "\n";
-  /* clang-format on */
+  infoFileStream << "# Relative path conversion top directories.\n"
+                    "set(CMAKE_RELATIVE_PATH_TOP_SOURCE \""
+                 << this->GetRelativePathTopSource() << "\")\n"
+                 << "set(CMAKE_RELATIVE_PATH_TOP_BINARY \""
+                 << this->GetRelativePathTopBinary() << "\")\n"
+                 << '\n';
 
   // Tell the dependency scanner to use unix paths if necessary.
   if (cmSystemTools::GetForceUnixPaths()) {
-    /* clang-format off */
-    infoFileStream
-      << "# Force unix paths in dependencies.\n"
-      << "set(CMAKE_FORCE_UNIX_PATHS 1)\n"
-      << "\n";
-    /* clang-format on */
+    infoFileStream << "# Force unix paths in dependencies.\n"
+                      "set(CMAKE_FORCE_UNIX_PATHS 1)\n"
+                      "\n";
   }
 
   // Store the include regular expressions for this directory.
   infoFileStream << "\n"
-                 << "# The C and CXX include file regular expressions for "
-                 << "this directory.\n";
-  infoFileStream << "set(CMAKE_C_INCLUDE_REGEX_SCAN ";
+                    "# The C and CXX include file regular expressions for "
+                    "this directory.\n"
+                    "set(CMAKE_C_INCLUDE_REGEX_SCAN ";
   cmLocalUnixMakefileGenerator3::WriteCMakeArgument(
     infoFileStream, this->Makefile->GetIncludeRegularExpression());
-  infoFileStream << ")\n";
-  infoFileStream << "set(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
+  infoFileStream << ")\n"
+                    "set(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
   cmLocalUnixMakefileGenerator3::WriteCMakeArgument(
     infoFileStream, this->Makefile->GetComplainRegularExpression());
-  infoFileStream << ")\n";
   infoFileStream
-    << "set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n";
-  infoFileStream << "set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN "
-                    "${CMAKE_C_INCLUDE_REGEX_COMPLAIN})\n";
+    << ")\n"
+    << "set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n"
+       "set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN "
+       "${CMAKE_C_INCLUDE_REGEX_COMPLAIN})\n";
 }
 
 std::string cmLocalUnixMakefileGenerator3::ConvertToFullPath(
@@ -583,7 +577,7 @@ void cmLocalUnixMakefileGenerator3::WriteMakeRule(
   if (symbolic) {
     if (cmValue sym =
           this->Makefile->GetDefinition("CMAKE_MAKE_SYMBOLIC_RULE")) {
-      os << tgt << space << ": " << *sym << "\n";
+      os << tgt << space << ": " << *sym << '\n';
     }
   }
 
@@ -603,12 +597,12 @@ void cmLocalUnixMakefileGenerator3::WriteMakeRule(
 
   if (!commands.empty()) {
     // Write the list of commands.
-    os << cmWrap("\t", commands, "", "\n") << "\n";
+    os << cmWrap("\t", commands, "", "\n") << '\n';
   }
   if (symbolic && !this->IsWatcomWMake()) {
-    os << ".PHONY : " << tgt << "\n";
+    os << ".PHONY : " << tgt << '\n';
   }
-  os << "\n";
+  os << '\n';
   // Add the output to the local help if requested.
   if (in_help) {
     this->LocalHelp.push_back(target);
@@ -636,27 +630,24 @@ void cmLocalUnixMakefileGenerator3::WriteMakeVariables(
 {
   this->WriteDivider(makefileStream);
   makefileStream << "# Set environment variables for the build.\n"
-                 << "\n";
+                    "\n";
   cmGlobalUnixMakefileGenerator3* gg =
     static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
   if (gg->DefineWindowsNULL) {
     makefileStream << "!IF \"$(OS)\" == \"Windows_NT\"\n"
-                   << "NULL=\n"
-                   << "!ELSE\n"
-                   << "NULL=nul\n"
-                   << "!ENDIF\n";
+                      "NULL=\n"
+                      "!ELSE\n"
+                      "NULL=nul\n"
+                      "!ENDIF\n";
   }
   if (this->IsWindowsShell()) {
     makefileStream << "SHELL = cmd.exe\n"
-                   << "\n";
+                      "\n";
   } else {
 #if !defined(__VMS)
-    /* clang-format off */
-      makefileStream
-        << "# The shell in which to execute make rules.\n"
-        << "SHELL = /bin/sh\n"
-        << "\n";
-/* clang-format on */
+    makefileStream << "# The shell in which to execute make rules.\n"
+                      "SHELL = /bin/sh\n"
+                      "\n";
 #endif
   }
 
@@ -667,38 +658,32 @@ void cmLocalUnixMakefileGenerator3::WriteMakeVariables(
       cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
   }
 
-  /* clang-format off */
   makefileStream
     << "# The CMake executable.\n"
-    << "CMAKE_COMMAND = "
+       "CMAKE_COMMAND = "
     << cmakeShellCommand
     << "\n"
-    << "\n";
-  makefileStream
-    << "# The command to remove a file.\n"
-    << "RM = "
+       "\n"
+       "# The command to remove a file.\n"
+       "RM = "
     << cmakeShellCommand
     << " -E rm -f\n"
-    << "\n";
-  makefileStream
-    << "# Escaping for special characters.\n"
-    << "EQUALS = =\n"
-    << "\n";
-  makefileStream
-    << "# The top-level source directory on which CMake was run.\n"
-    << "CMAKE_SOURCE_DIR = "
-    << this->ConvertToOutputFormat(
-      this->GetSourceDirectory(), cmOutputConverter::SHELL)
+       "\n"
+       "# Escaping for special characters.\n"
+       "EQUALS = =\n"
+       "\n"
+       "# The top-level source directory on which CMake was run.\n"
+       "CMAKE_SOURCE_DIR = "
+    << this->ConvertToOutputFormat(this->GetSourceDirectory(),
+                                   cmOutputConverter::SHELL)
     << "\n"
-    << "\n";
-  makefileStream
-    << "# The top-level build directory on which CMake was run.\n"
-    << "CMAKE_BINARY_DIR = "
-    << this->ConvertToOutputFormat(
-      this->GetBinaryDirectory(), cmOutputConverter::SHELL)
+       "\n"
+       "# The top-level build directory on which CMake was run.\n"
+       "CMAKE_BINARY_DIR = "
+    << this->ConvertToOutputFormat(this->GetBinaryDirectory(),
+                                   cmOutputConverter::SHELL)
     << "\n"
-    << "\n";
-  /* clang-format on */
+       "\n";
 }
 
 void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsTop(
@@ -706,7 +691,7 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsTop(
 {
   this->WriteDivider(makefileStream);
   makefileStream << "# Special targets provided by cmake.\n"
-                 << "\n";
+                    "\n";
 
   std::vector<std::string> no_commands;
   std::vector<std::string> no_depends;
@@ -740,31 +725,20 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsTop(
     // Switch on WMake feature, if an error or interrupt occurs during
     // makefile processing, the current target being made may be deleted
     // without prompting (the same as command line -e option).
-    /* clang-format off */
-    makefileStream <<
-      "\n"
-      ".ERASE\n"
-      "\n"
-      ;
-    /* clang-format on */
+    makefileStream << "\n"
+                      ".ERASE\n"
+                      "\n";
   }
   if (this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE")) {
-    /* clang-format off */
-    makefileStream
-      << "# Produce verbose output by default.\n"
-      << "VERBOSE = 1\n"
-      << "\n";
-    /* clang-format on */
+    makefileStream << "# Produce verbose output by default.\n"
+                      "VERBOSE = 1\n"
+                      "\n";
   }
   if (this->IsWatcomWMake()) {
-    /* clang-format off */
-    makefileStream <<
-      "!ifndef VERBOSE\n"
-      ".SILENT\n"
-      "!endif\n"
-      "\n"
-      ;
-    /* clang-format on */
+    makefileStream << "!ifndef VERBOSE\n"
+                      ".SILENT\n"
+                      "!endif\n"
+                      "\n";
   } else {
     makefileStream << "# Command-line flag to silence nested $(MAKE).\n"
                       "$(VERBOSE)MAKESILENT = -s\n"
@@ -809,7 +783,7 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsBottom(
 {
   this->WriteDivider(makefileStream);
   makefileStream << "# Special targets to cleanup operation of make.\n"
-                 << "\n";
+                    "\n";
 
   // Write special "cmake_check_build_system" target to run cmake with
   // the --check-build-system flag.
@@ -1114,7 +1088,7 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
     fout << "file(REMOVE_RECURSE\n";
     for (std::string const& file : files) {
       std::string fc = this->MaybeRelativeToCurBinDir(file);
-      fout << "  " << cmOutputConverter::EscapeForCMake(fc) << "\n";
+      fout << "  " << cmOutputConverter::EscapeForCMake(fc) << '\n';
     }
     fout << ")\n";
   }
@@ -1134,11 +1108,11 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
       languages, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
     /* clang-format off */
     fout << "\n"
-         << "# Per-language clean rules from dependency scanning.\n"
-         << "foreach(lang " << cmJoin(languages, " ") << ")\n"
-         << "  include(" << this->GetTargetDirectory(target)
+            "# Per-language clean rules from dependency scanning.\n"
+            "foreach(lang " << cmJoin(languages, " ") << ")\n"
+            "  include(" << this->GetTargetDirectory(target)
          << "/cmake_clean_${lang}.cmake OPTIONAL)\n"
-         << "endforeach()\n";
+            "endforeach()\n";
     /* clang-format on */
   }
 }
@@ -1173,7 +1147,7 @@ void cmLocalUnixMakefileGenerator3::AppendDirectoryCleanCommand(
     for (std::string const& cfl : cleanFiles) {
       std::string fc = rootLG->MaybeRelativeToCurBinDir(
         cmSystemTools::CollapseFullPath(cfl, currentBinaryDir));
-      fout << "  " << cmOutputConverter::EscapeForCMake(fc) << "\n";
+      fout << "  " << cmOutputConverter::EscapeForCMake(fc) << '\n';
     }
     fout << ")\n";
   }
@@ -1235,17 +1209,14 @@ void cmLocalUnixMakefileGenerator3::AppendEcho(
             "@$(CMAKE_COMMAND) -E cmake_echo_color \"--switch=$(COLOR)\" ",
             color_name);
           if (progress) {
-            cmd += "--progress-dir=";
-            cmd += this->ConvertToOutputFormat(progress->Dir,
-                                               cmOutputConverter::SHELL);
-            cmd += " ";
-            cmd += "--progress-num=";
-            cmd += progress->Arg;
-            cmd += " ";
+            cmd = cmStrCat(cmd, "--progress-dir=",
+                           this->ConvertToOutputFormat(
+                             progress->Dir, cmOutputConverter::SHELL),
+                           " --progress-num=", progress->Arg, ' ');
           }
           cmd += this->EscapeForShell(line);
         }
-        commands.push_back(std::move(cmd));
+        commands.emplace_back(std::move(cmd));
       }
 
       // Reset the line to empty.
@@ -1586,7 +1557,7 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies(
 #ifndef CMAKE_BOOTSTRAP
     else if (lang == "Fortran") {
       ruleFileStream << "# Note that incremental build could trigger "
-                     << "a call to cmake_copy_f90_mod on each re-build\n";
+                        "a call to cmake_copy_f90_mod on each re-build\n";
       scanner = cm::make_unique<cmDependsFortran>(this);
     } else if (lang == "Java") {
       scanner = cm::make_unique<cmDependsJava>();
@@ -1674,7 +1645,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
   // Write all global targets
   this->WriteDivider(ruleFileStream);
   ruleFileStream << "# Targets provided globally by CMake.\n"
-                 << "\n";
+                    "\n";
   const auto& targets = this->GetGeneratorTargets();
   for (const auto& gt : targets) {
     if (gt->GetType() == cmStateEnums::GLOBAL_TARGET) {
@@ -1902,8 +1873,8 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
 {
   // To enable dependencies filtering
   cmakefileStream << "\n"
-                  << "# Consider dependencies only in project.\n"
-                  << "set(CMAKE_DEPENDS_IN_PROJECT_ONLY "
+                     "# Consider dependencies only in project.\n"
+                     "set(CMAKE_DEPENDS_IN_PROJECT_ONLY "
                   << (cmIsOn(this->Makefile->GetSafeDefinition(
                         "CMAKE_DEPENDS_IN_PROJECT_ONLY"))
                         ? "ON"
@@ -1920,8 +1891,8 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
 
   // list the languages
   cmakefileStream << "# The set of languages for which implicit "
-                     "dependencies are needed:\n";
-  cmakefileStream << "set(CMAKE_DEPENDS_LANGUAGES\n";
+                     "dependencies are needed:\n"
+                     "set(CMAKE_DEPENDS_LANGUAGES\n";
   for (auto const& implicitLang : implicitLangs) {
     cmakefileStream << "  \"" << implicitLang.first << "\"\n";
     if (requireFortran && implicitLang.first == "Fortran"_s) {
@@ -1940,14 +1911,14 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
     for (auto const& implicitLang : implicitLangs) {
       const auto& lang = implicitLang.first;
 
-      cmakefileStream << "set(CMAKE_DEPENDS_CHECK_" << lang << "\n";
+      cmakefileStream << "set(CMAKE_DEPENDS_CHECK_" << lang << '\n';
       auto const& implicitPairs = implicitLang.second;
 
       // for each file pair
       for (auto const& implicitPair : implicitPairs) {
         for (auto const& di : implicitPair.second) {
-          cmakefileStream << "  \"" << di << "\" ";
-          cmakefileStream << "\"" << implicitPair.first << "\"\n";
+          cmakefileStream << "  \"" << di << "\" \"" << implicitPair.first
+                          << "\"\n";
         }
       }
       cmakefileStream << "  )\n";
@@ -1966,32 +1937,31 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
         std::string smodExt =
           this->Makefile->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_EXT");
         cmakefileStream << "set(CMAKE_Fortran_SUBMODULE_SEP \"" << smodSep
-                        << "\")\n";
-        cmakefileStream << "set(CMAKE_Fortran_SUBMODULE_EXT \"" << smodExt
-                        << "\")\n";
+                        << "\")\n"
+                           "set(CMAKE_Fortran_SUBMODULE_EXT \""
+                        << smodExt << "\")\n";
       }
 
       // Build a list of preprocessor definitions for the target.
       std::set<std::string> defines;
       this->GetTargetDefines(target, this->GetConfigName(), lang, defines);
       if (!defines.empty()) {
-        /* clang-format off */
-      cmakefileStream
-        << "\n"
-        << "# Preprocessor definitions for this target.\n"
-        << "set(CMAKE_TARGET_DEFINITIONS_" << lang << "\n";
-        /* clang-format on */
+        cmakefileStream << "\n"
+                           "# Preprocessor definitions for this target.\n"
+                           "set(CMAKE_TARGET_DEFINITIONS_"
+                        << lang << '\n';
         for (std::string const& define : defines) {
           cmakefileStream << "  " << cmOutputConverter::EscapeForCMake(define)
-                          << "\n";
+                          << '\n';
         }
         cmakefileStream << "  )\n";
       }
 
       // Target-specific include directories:
       cmakefileStream << "\n"
-                      << "# The include file search paths:\n";
-      cmakefileStream << "set(CMAKE_" << lang << "_TARGET_INCLUDE_PATH\n";
+                         "# The include file search paths:\n"
+                         "set(CMAKE_"
+                      << lang << "_TARGET_INCLUDE_PATH\n";
       std::vector<std::string> includes;
 
       this->GetIncludeDirectories(includes, target, lang,
@@ -2023,7 +1993,7 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
       cmakefileStream << "\nset(CMAKE_INCLUDE_TRANSFORMS\n";
       for (std::string const& tr : transformRules) {
         cmakefileStream << "  " << cmOutputConverter::EscapeForCMake(tr)
-                        << "\n";
+                        << '\n';
       }
       cmakefileStream << "  )\n";
     }
@@ -2033,8 +2003,8 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
     this->GetImplicitDepends(target, cmDependencyScannerKind::Compiler);
 
   // list the dependency files managed by the compiler
-  cmakefileStream << "\n# The set of dependency files which are needed:\n";
-  cmakefileStream << "set(CMAKE_DEPENDS_DEPENDENCY_FILES\n";
+  cmakefileStream << "\n# The set of dependency files which are needed:\n"
+                     "set(CMAKE_DEPENDS_DEPENDENCY_FILES\n";
   for (auto const& compilerLang : compilerLangs) {
     auto const& compilerPairs = compilerLang.second;
     if (compilerLang.first == "CUSTOM"_s) {
@@ -2078,9 +2048,12 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
 void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
 {
   os << "# CMAKE generated file: DO NOT EDIT!\n"
-     << "# Generated by \"" << this->GlobalGenerator->GetName() << "\""
-     << " Generator, CMake Version " << cmVersion::GetMajorVersion() << "."
-     << cmVersion::GetMinorVersion() << "\n\n";
+        "# Generated by \""
+     << this->GlobalGenerator->GetName()
+     << "\""
+        " Generator, CMake Version "
+     << cmVersion::GetMajorVersion() << '.' << cmVersion::GetMinorVersion()
+     << "\n\n";
 }
 
 std::string cmLocalUnixMakefileGenerator3::GetRecursiveMakeCall(

+ 117 - 133
Source/cmLocalVisualStudio7Generator.cxx

@@ -185,7 +185,7 @@ void cmLocalVisualStudio7Generator::WriteStampFiles()
   listFiles.erase(new_end, listFiles.end());
 
   for (const std::string& lf : listFiles) {
-    depFile << lf << "\n";
+    depFile << lf << '\n';
   }
 }
 
@@ -571,7 +571,7 @@ public:
   void Start(const char* tool)
   {
     this->First = true;
-    this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
+    this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << '"';
   }
   void Finish()
   {
@@ -579,7 +579,7 @@ public:
     if (!this->First) {
       std::string finishScript =
         this->LG->FinishConstructScript(VsProjectType::vcxproj);
-      this->Stream << this->LG->EscapeForXML(finishScript) << "\"";
+      this->Stream << this->LG->EscapeForXML(finishScript) << '"';
     }
 
     this->Stream << "/>\n";
@@ -627,8 +627,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
   cmGlobalVisualStudio7Generator* gg =
     static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
   fout << "\t\t<Configuration\n"
-       << "\t\t\tName=\"" << configName << "|" << gg->GetPlatformName()
-       << "\"\n";
+          "\t\t\tName=\""
+       << configName << '|' << gg->GetPlatformName() << "\"\n";
   // This is an internal type to Visual Studio, it seems that:
   // 4 == static library
   // 2 == dll
@@ -777,20 +777,20 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
       target->GetType() == cmStateEnums::OBJECT_LIBRARY
       ? intermediateDir
       : target->GetDirectory(configName);
-    /* clang-format off */
     fout << "\t\t\tOutputDirectory=\""
          << this->ConvertToXMLOutputPathSingle(outDir) << "\"\n";
-    /* clang-format on */
   }
 
-  /* clang-format off */
   fout << "\t\t\tIntermediateDirectory=\""
        << this->ConvertToXMLOutputPath(intermediateDir)
        << "\"\n"
-       << "\t\t\tConfigurationType=\"" << configType << "\"\n"
-       << "\t\t\tUseOfMFC=\"" << mfcFlag << "\"\n"
-       << "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
-  /* clang-format on */
+          "\t\t\tConfigurationType=\""
+       << configType
+       << "\"\n"
+          "\t\t\tUseOfMFC=\""
+       << mfcFlag
+       << "\"\n"
+          "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"false\"\n";
 
   if (this->FortranProject) {
     // Intel Fortran >= 15.0 uses TargetName property.
@@ -826,7 +826,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
     tool = "VFFortranCompilerTool";
   }
   fout << "\t\t\t<Tool\n"
-       << "\t\t\t\tName=\"" << tool << "\"\n";
+          "\t\t\t\tName=\""
+       << tool << "\"\n";
   if (this->FortranProject) {
     cmValue target_mod_dir = target->GetProperty("Fortran_MODULE_DIRECTORY");
     std::string modDir;
@@ -854,39 +855,25 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
   fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
   if (gg->IsMarmasmEnabled() && !this->FortranProject) {
     Options marmasmOptions(this, Options::MarmasmCompiler, nullptr, nullptr);
-    /* clang-format off */
-    fout <<
-      "\t\t\t<Tool\n"
-      "\t\t\t\tName=\"MARMASM\"\n"
-      ;
-    /* clang-format on */
+    fout << "\t\t\t<Tool\n"
+            "\t\t\t\tName=\"MARMASM\"\n";
     targetOptions.OutputAdditionalIncludeDirectories(fout, 4, "ASM_MARMASM");
     // Use same preprocessor definitions as VCCLCompilerTool.
     targetOptions.OutputPreprocessorDefinitions(fout, 4, "ASM_MARMASM");
     marmasmOptions.OutputFlagMap(fout, 4);
-    /* clang-format off */
-    fout <<
-      "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
-      "\t\t\t/>\n";
-    /* clang-format on */
+    fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
+            "\t\t\t/>\n";
   }
   if (gg->IsMasmEnabled() && !this->FortranProject) {
     Options masmOptions(this, Options::MasmCompiler, nullptr, nullptr);
-    /* clang-format off */
-    fout <<
-      "\t\t\t<Tool\n"
-      "\t\t\t\tName=\"MASM\"\n"
-      ;
-    /* clang-format on */
+    fout << "\t\t\t<Tool\n"
+            "\t\t\t\tName=\"MASM\"\n";
     targetOptions.OutputAdditionalIncludeDirectories(fout, 4, "ASM_MASM");
     // Use same preprocessor definitions as VCCLCompilerTool.
     targetOptions.OutputPreprocessorDefinitions(fout, 4, "ASM_MASM");
     masmOptions.OutputFlagMap(fout, 4);
-    /* clang-format off */
-    fout <<
-      "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
-      "\t\t\t/>\n";
-    /* clang-format on */
+    fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
+            "\t\t\t/>\n";
   }
   tool = "VCCustomBuildTool";
   if (this->FortranProject) {
@@ -916,13 +903,13 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
   } else {
     fout << "\t\t\t\tTargetEnvironment=\"1\"\n";
   }
-  fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n";
-  fout << "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n";
-  fout << "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n";
-  fout << "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n";
-  fout << "\t\t\t\tDLLDataFileName=\"\"\n";
-  fout << "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n";
-  fout << "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
+  fout << "\t\t\t\tGenerateStublessProxies=\"true\"\n"
+          "\t\t\t\tTypeLibraryName=\"$(InputName).tlb\"\n"
+          "\t\t\t\tOutputDirectory=\"$(IntDir)\"\n"
+          "\t\t\t\tHeaderFileName=\"$(InputName).h\"\n"
+          "\t\t\t\tDLLDataFileName=\"\"\n"
+          "\t\t\t\tInterfaceIdentifierFileName=\"$(InputName)_i.c\"\n"
+          "\t\t\t\tProxyFileName=\"$(InputName)_p.c\"/>\n";
   // end of <Tool Name=VCMIDLTool
 
   // Add manifest tool settings.
@@ -931,11 +918,9 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
     if (this->FortranProject) {
       manifestTool = "VFManifestTool";
     }
-    /* clang-format off */
-    fout <<
-      "\t\t\t<Tool\n"
-      "\t\t\t\tName=\"" << manifestTool << "\"";
-    /* clang-format on */
+    fout << "\t\t\t<Tool\n"
+            "\t\t\t\tName=\""
+         << manifestTool << '"';
 
     std::vector<cmSourceFile const*> manifest_srcs;
     target->GetManifests(manifest_srcs, configName);
@@ -943,9 +928,9 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
       fout << "\n\t\t\t\tAdditionalManifestFiles=\"";
       for (cmSourceFile const* manifest : manifest_srcs) {
         std::string m = manifest->GetFullPath();
-        fout << this->ConvertToXMLOutputPath(m) << ";";
+        fout << this->ConvertToXMLOutputPath(m) << ';';
       }
-      fout << "\"";
+      fout << '"';
     }
 
     // Check if we need the FAT32 workaround.
@@ -1038,8 +1023,10 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
       const char* tool =
         this->FortranProject ? "VFLibrarianTool" : "VCLibrarianTool";
       fout << "\t\t\t<Tool\n"
-           << "\t\t\t\tName=\"" << tool << "\"\n";
-      fout << "\t\t\t\tOutputFile=\""
+              "\t\t\t\tName=\""
+           << tool
+           << "\"\n"
+              "\t\t\t\tOutputFile=\""
            << this->ConvertToXMLOutputPathSingle(libpath) << "\"/>\n";
       break;
     }
@@ -1052,7 +1039,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
         tool = "VFLibrarianTool";
       }
       fout << "\t\t\t<Tool\n"
-           << "\t\t\t\tName=\"" << tool << "\"\n";
+              "\t\t\t\tName=\""
+           << tool << "\"\n";
 
       if (this->FortranProject) {
         std::ostringstream libdeps;
@@ -1104,7 +1092,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
         tool = "VFLinkerTool";
       }
       fout << "\t\t\t<Tool\n"
-           << "\t\t\t\tName=\"" << tool << "\"\n";
+              "\t\t\t\tName=\""
+           << tool << "\"\n";
       if (!gg->NeedLinkLibraryDependencies(target)) {
         fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
       }
@@ -1115,7 +1104,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
       if (this->FortranProject) {
         this->Internal->OutputObjects(fout, target, configName, " ");
       }
-      fout << " ";
+      fout << ' ';
       this->Internal->OutputLibraries(fout, cli.GetItems());
       fout << "\"\n";
       temp =
@@ -1189,7 +1178,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
         tool = "VFLinkerTool";
       }
       fout << "\t\t\t<Tool\n"
-           << "\t\t\t\tName=\"" << tool << "\"\n";
+              "\t\t\t\tName=\""
+           << tool << "\"\n";
       if (!gg->NeedLinkLibraryDependencies(target)) {
         fout << "\t\t\t\tLinkLibraryDependencies=\"false\"\n";
       }
@@ -1217,7 +1207,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
       fout << "\"\n";
       std::string path = this->ConvertToXMLOutputPathSingle(
         target->GetPDBDirectory(configName));
-      fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/"
+      fout << "\t\t\t\tProgramDatabaseFile=\"" << path << '/'
            << targetNames.PDB << "\"\n";
       if (targetOptions.UsingDebugInfo()) {
         fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
@@ -1242,7 +1232,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
       std::string stackVar = cmStrCat("CMAKE_", linkLanguage, "_STACK_SIZE");
       cmValue stackVal = this->Makefile->GetDefinition(stackVar);
       if (stackVal) {
-        fout << "\t\t\t\tStackReserveSize=\"" << *stackVal << "\"";
+        fout << "\t\t\t\tStackReserveSize=\"" << *stackVal << '"';
       }
       temp = cmStrCat(
         target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact),
@@ -1774,14 +1764,15 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
         for (auto const& fci : fcinfo.FileConfigMap) {
           cmLVS7GFileConfig const& fc = fci.second;
           fout << "\t\t\t\t<FileConfiguration\n"
-               << "\t\t\t\t\tName=\"" << fci.first << "|"
-               << gg->GetPlatformName() << "\"";
+                  "\t\t\t\t\tName=\""
+               << fci.first << '|' << gg->GetPlatformName() << '"';
           if (fc.ExcludedFromBuild) {
             fout << " ExcludedFromBuild=\"true\"";
           }
-          fout << ">\n";
-          fout << "\t\t\t\t\t<Tool\n"
-               << "\t\t\t\t\tName=\"" << aCompilerTool << "\"\n";
+          fout << ">\n"
+                  "\t\t\t\t\t<Tool\n"
+                  "\t\t\t\t\tName=\""
+               << aCompilerTool << "\"\n";
           if (!fc.CompileFlags.empty() || !fc.CompileDefs.empty() ||
               !fc.CompileDefsConfig.empty() || !fc.IncludeDirs.empty()) {
             Options::Tool tool = Options::Compiler;
@@ -1814,7 +1805,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
                  << "\"\n";
           }
           fout << "\t\t\t\t\t/>\n"
-               << "\t\t\t\t</FileConfiguration>\n";
+                  "\t\t\t\t</FileConfiguration>\n";
         }
       }
       fout << "\t\t\t</File>\n";
@@ -1853,13 +1844,15 @@ void cmLocalVisualStudio7Generator::WriteCustomRule(
   for (std::string const& config : configs) {
     cmCustomCommandGenerator ccg(command, config, this);
     cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[config];
-    fout << "\t\t\t\t<FileConfiguration\n";
-    fout << "\t\t\t\t\tName=\"" << config << "|" << gg->GetPlatformName()
-         << "\">\n";
+    fout << "\t\t\t\t<FileConfiguration\n"
+            "\t\t\t\t\tName=\""
+         << config << '|' << gg->GetPlatformName() << "\">\n";
     if (!fc.CompileFlags.empty()) {
       fout << "\t\t\t\t\t<Tool\n"
-           << "\t\t\t\t\tName=\"" << compileTool << "\"\n"
-           << "\t\t\t\t\tAdditionalOptions=\""
+              "\t\t\t\t\tName=\""
+           << compileTool
+           << "\"\n"
+              "\t\t\t\t\tAdditionalOptions=\""
            << this->EscapeForXML(fc.CompileFlags) << "\"/>\n";
     }
 
@@ -1871,12 +1864,12 @@ void cmLocalVisualStudio7Generator::WriteCustomRule(
     script += this->FinishConstructScript(VsProjectType::vcxproj);
     /* clang-format off */
     fout << "\t\t\t\t\t<Tool\n"
-         << "\t\t\t\t\tName=\"" << customTool << "\"\n"
+            "\t\t\t\t\tName=\"" << customTool << "\"\n"
          << "\t\t\t\t\tDescription=\""
          << this->EscapeForXML(comment) << "\"\n"
-         << "\t\t\t\t\tCommandLine=\""
+            "\t\t\t\t\tCommandLine=\""
          << this->EscapeForXML(script) << "\"\n"
-         << "\t\t\t\t\tAdditionalDependencies=\"";
+            "\t\t\t\t\tAdditionalDependencies=\"";
     /* clang-format on */
     if (ccg.GetDepends().empty()) {
       // There are no real dependencies.  Produce an artificial one to
@@ -1896,8 +1889,8 @@ void cmLocalVisualStudio7Generator::WriteCustomRule(
         }
       }
     }
-    fout << "\"\n";
-    fout << "\t\t\t\t\tOutputs=\"";
+    fout << "\"\n"
+            "\t\t\t\t\tOutputs=\"";
     if (ccg.GetOutputs().empty()) {
       fout << source << "_force";
     } else {
@@ -1908,8 +1901,8 @@ void cmLocalVisualStudio7Generator::WriteCustomRule(
         sep = ";";
       }
     }
-    fout << "\"/>\n";
-    fout << "\t\t\t\t</FileConfiguration>\n";
+    fout << "\"/>\n"
+            "\t\t\t\t</FileConfiguration>\n";
   }
 }
 
@@ -1917,11 +1910,11 @@ void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout,
                                                           const char* group,
                                                           const char*)
 {
-  /* clang-format off */
   fout << "\t\t<Filter\n"
-       << "\t\t\tName=\"" << group << "\"\n"
-       << "\t\t\tFilter=\"\">\n";
-  /* clang-format on */
+          "\t\t\tName=\""
+       << group
+       << "\"\n"
+          "\t\t\tFilter=\"\">\n";
 }
 
 void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout)
@@ -1990,8 +1983,8 @@ void cmLocalVisualStudio7Generator::WriteProjectSCC(std::ostream& fout,
   if (vsProvider && vsLocalpath && vsProjectname) {
     /* clang-format off */
     fout << "\tSccProjectName=\"" << *vsProjectname << "\"\n"
-         << "\tSccLocalPath=\"" << *vsLocalpath << "\"\n"
-         << "\tSccProvider=\"" << *vsProvider << "\"\n";
+            "\tSccLocalPath=\"" << *vsLocalpath << "\"\n"
+            "\tSccProvider=\"" << *vsProvider << "\"\n";
     /* clang-format on */
 
     cmValue vsAuxPath = target->GetProperty("VS_SCC_AUXPATH");
@@ -2007,13 +2000,12 @@ void cmLocalVisualStudio7Generator::WriteProjectStartFortran(
 
   cmGlobalVisualStudio7Generator* gg =
     static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
-  /* clang-format off */
-  fout << R"(<?xml version="1.0" encoding = ")"
-       << gg->Encoding() << "\"?>\n"
-       << "<VisualStudioProject\n"
-       << "\tProjectCreator=\"Intel Fortran\"\n"
-       << "\tVersion=\"" << gg->GetIntelProjectVersion() << "\"\n";
-  /* clang-format on */
+  fout << R"(<?xml version="1.0" encoding = ")" << gg->Encoding()
+       << "\"?>\n"
+          "<VisualStudioProject\n"
+          "\tProjectCreator=\"Intel Fortran\"\n"
+          "\tVersion=\""
+       << gg->GetIntelProjectVersion() << "\"\n";
   cmValue p = target->GetProperty("VS_KEYWORD");
   const char* keyword = p ? p->c_str() : "Console Application";
   const char* projectType = nullptr;
@@ -2050,10 +2042,10 @@ void cmLocalVisualStudio7Generator::WriteProjectStartFortran(
   this->WriteProjectSCC(fout, target);
   /* clang-format off */
   fout<< "\tKeyword=\"" << keyword << "\">\n"
-       << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\">\n"
-       << "\t<Platforms>\n"
-       << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
-       << "\t</Platforms>\n";
+         "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\">\n"
+         "\t<Platforms>\n"
+         "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
+         "\t</Platforms>\n";
   /* clang-format on */
 }
 
@@ -2069,20 +2061,20 @@ void cmLocalVisualStudio7Generator::WriteProjectStart(
   cmGlobalVisualStudio7Generator* gg =
     static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
 
-  /* clang-format off */
-  fout << R"(<?xml version="1.0" encoding = ")"
-       << gg->Encoding() << "\"?>\n"
-       << "<VisualStudioProject\n"
-       << "\tProjectType=\"Visual C++\"\n";
-  /* clang-format on */
-  fout << "\tVersion=\"" << (static_cast<uint16_t>(gg->GetVersion()) / 10)
-       << ".00\"\n";
+  fout << R"(<?xml version="1.0" encoding = ")" << gg->Encoding()
+       << "\"?>\n"
+          "<VisualStudioProject\n"
+          "\tProjectType=\"Visual C++\"\n"
+          "\tVersion=\""
+       << (static_cast<uint16_t>(gg->GetVersion()) / 10) << ".00\"\n";
   cmValue p = target->GetProperty("PROJECT_LABEL");
   const std::string projLabel = p ? *p : libName;
   p = target->GetProperty("VS_KEYWORD");
   const std::string keyword = p ? *p : "Win32Proj";
-  fout << "\tName=\"" << projLabel << "\"\n";
-  fout << "\tProjectGUID=\"{" << gg->GetGUID(libName) << "}\"\n";
+  fout << "\tName=\"" << projLabel
+       << "\"\n"
+          "\tProjectGUID=\"{"
+       << gg->GetGUID(libName) << "}\"\n";
   this->WriteProjectSCC(fout, target);
   if (cmValue targetFrameworkVersion =
         target->GetProperty("VS_DOTNET_TARGET_FRAMEWORK_VERSION")) {
@@ -2090,31 +2082,23 @@ void cmLocalVisualStudio7Generator::WriteProjectStart(
   }
   /* clang-format off */
   fout << "\tKeyword=\"" << keyword << "\">\n"
-       << "\t<Platforms>\n"
-       << "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
-       << "\t</Platforms>\n";
+          "\t<Platforms>\n"
+          "\t\t<Platform\n\t\t\tName=\"" << gg->GetPlatformName() << "\"/>\n"
+          "\t</Platforms>\n";
   /* clang-format on */
   if (gg->IsMarmasmEnabled()) {
-    /* clang-format off */
-    fout <<
-      "\t<ToolFiles>\n"
-      "\t\t<DefaultToolFile\n"
-      "\t\t\tFileName=\"marmasm.rules\"\n"
-      "\t\t/>\n"
-      "\t</ToolFiles>\n"
-      ;
-    /* clang-format on */
+    fout << "\t<ToolFiles>\n"
+            "\t\t<DefaultToolFile\n"
+            "\t\t\tFileName=\"marmasm.rules\"\n"
+            "\t\t/>\n"
+            "\t</ToolFiles>\n";
   }
   if (gg->IsMasmEnabled()) {
-    /* clang-format off */
-    fout <<
-      "\t<ToolFiles>\n"
-      "\t\t<DefaultToolFile\n"
-      "\t\t\tFileName=\"masm.rules\"\n"
-      "\t\t/>\n"
-      "\t</ToolFiles>\n"
-      ;
-    /* clang-format on */
+    fout << "\t<ToolFiles>\n"
+            "\t\t<DefaultToolFile\n"
+            "\t\t\tFileName=\"masm.rules\"\n"
+            "\t\t/>\n"
+            "\t</ToolFiles>\n";
   }
 }
 
@@ -2127,18 +2111,20 @@ void cmLocalVisualStudio7Generator::WriteVCProjFooter(
     if (cmHasLiteralPrefix(key, "VS_GLOBAL_")) {
       std::string name = key.substr(10);
       if (!name.empty()) {
-        /* clang-format off */
         fout << "\t\t<Global\n"
-             << "\t\t\tName=\"" << name << "\"\n"
-             << "\t\t\tValue=\"" << target->GetProperty(key) << "\"\n"
-             << "\t\t/>\n";
-        /* clang-format on */
+                "\t\t\tName=\""
+             << name
+             << "\"\n"
+                "\t\t\tValue=\""
+             << target->GetProperty(key)
+             << "\"\n"
+                "\t\t/>\n";
       }
     }
   }
 
   fout << "\t</Globals>\n"
-       << "</VisualStudioProject>\n";
+          "</VisualStudioProject>\n";
 }
 
 std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
@@ -2177,10 +2163,8 @@ void cmVS7GeneratorOptions::OutputFlag(std::ostream& fout, int indent,
   fout.fill('\t');
   fout.width(indent);
   // write an empty string to get the fill level indent to print
-  fout << "";
-  fout << flag << "=\"";
-  fout << cmLocalVisualStudio7GeneratorEscapeForXML(content);
-  fout << "\"\n";
+  fout << "" << flag << "=\""
+       << cmLocalVisualStudio7GeneratorEscapeForXML(content) << "\"\n";
 }
 
 // This class is used to parse an existing vs 7 project

+ 29 - 31
Source/cmLocalVisualStudioGenerator.cxx

@@ -18,6 +18,7 @@
 #include "cmOutputConverter.h"
 #include "cmSourceFile.h"
 #include "cmStateTypes.h"
+#include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 #include "cmValue.h"
 
@@ -136,12 +137,12 @@ std::string cmLocalVisualStudioGenerator::ConstructScript(
   std::string newline;
 
   // Line to check for error between commands.
-  std::string check_error = newline_text;
+  std::string check_error;
   if (useLocal) {
-    check_error += "if %errorlevel% neq 0 goto :cmEnd";
+    check_error = cmStrCat(newline_text, "if %errorlevel% neq 0 goto :cmEnd");
   } else {
-    check_error += "if errorlevel 1 goto ";
-    check_error += this->GetReportErrorLabel();
+    check_error = cmStrCat(newline_text, "if errorlevel 1 goto ",
+                           this->GetReportErrorLabel());
   }
 
   // Store the script in a string.
@@ -149,26 +150,22 @@ std::string cmLocalVisualStudioGenerator::ConstructScript(
 
   // Open a local context.
   if (useLocal) {
-    script += newline;
+    script = cmStrCat(newline, "setlocal");
     newline = newline_text;
-    script += "setlocal";
   }
 
   if (!workingDirectory.empty()) {
     // Change the working directory.
-    script += newline;
+    script = cmStrCat(script, newline, "cd ",
+                      this->ConvertToOutputFormat(workingDirectory, SHELL),
+                      check_error);
     newline = newline_text;
-    script += "cd ";
-    script += this->ConvertToOutputFormat(workingDirectory, SHELL);
-    script += check_error;
 
     // Change the working drive.
     if (workingDirectory.size() > 1 && workingDirectory[1] == ':') {
-      script += newline;
+      script = cmStrCat(script, newline, workingDirectory[0],
+                        workingDirectory[1], check_error);
       newline = newline_text;
-      script += workingDirectory[0];
-      script += workingDirectory[1];
-      script += check_error;
     }
   }
 
@@ -178,11 +175,8 @@ std::string cmLocalVisualStudioGenerator::ConstructScript(
     cmValue extraPath =
       this->Makefile->GetDefinition("CMAKE_MSVCIDE_RUN_PATH");
     if (extraPath) {
-      script += newline;
+      script = cmStrCat(script, newline, "set PATH=", *extraPath, ";%PATH%");
       newline = newline_text;
-      script += "set PATH=";
-      script += *extraPath;
-      script += ";%PATH%";
     }
   }
 
@@ -227,19 +221,23 @@ std::string cmLocalVisualStudioGenerator::ConstructScript(
 
   // Close the local context.
   if (useLocal) {
-    script += newline;
-    script += ":cmEnd";
-    script += newline;
-    script += "endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone";
-    script += newline;
-    script += ":cmErrorLevel";
-    script += newline;
-    script += "exit /b %1";
-    script += newline;
-    script += ":cmDone";
-    script += newline;
-    script += "if %errorlevel% neq 0 goto ";
-    script += this->GetReportErrorLabel();
+    // clang-format off
+    script = cmStrCat(
+        script
+      , newline
+      , ":cmEnd"
+      , newline
+      , "endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone"
+      , newline
+      , ":cmErrorLevel"
+      , newline
+      , "exit /b %1"
+      , newline
+      , ":cmDone"
+      , newline
+      , "if %errorlevel% neq 0 goto ", this->GetReportErrorLabel()
+      );
+    // clang-format on
   }
 
   return script;

+ 4 - 3
Source/cmMakefileUtilityTargetGenerator.cxx

@@ -55,8 +55,9 @@ void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
     cmGeneratedFileStream depFileStream(
       dependFile, false, this->GlobalGenerator->GetMakefileEncoding());
     depFileStream << "# Empty custom commands generated dependencies file for "
-                  << this->GeneratorTarget->GetName() << ".\n"
-                  << "# This may be replaced when dependencies are built.\n";
+                  << this->GeneratorTarget->GetName()
+                  << ".\n"
+                     "# This may be replaced when dependencies are built.\n";
   }
 
   std::string dependTimestamp =
@@ -66,7 +67,7 @@ void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
     cmGeneratedFileStream depFileStream(
       dependTimestamp, false, this->GlobalGenerator->GetMakefileEncoding());
     depFileStream << "# CMAKE generated file: DO NOT EDIT!\n"
-                  << "# Timestamp file for custom commands dependencies "
+                     "# Timestamp file for custom commands dependencies "
                      "management for "
                   << this->GeneratorTarget->GetName() << ".\n";
   }

+ 1 - 1
Source/cmNinjaTargetGenerator.cxx

@@ -1273,7 +1273,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements(
                                            build);
   }
 
-  this->GetImplFileStream(fileConfig) << "\n";
+  this->GetImplFileStream(fileConfig) << '\n';
 }
 
 void cmNinjaTargetGenerator::GenerateSwiftOutputFileMap(