瀏覽代碼

generated-scripts: simplify `if` conditions

Ben Boeckel 3 年之前
父節點
當前提交
d74761b181
共有 3 個文件被更改,包括 11 次插入14 次删除
  1. 7 8
      Source/cmExportFileGenerator.cxx
  2. 2 2
      Source/cmInstallGenerator.cxx
  3. 2 4
      Source/cmScriptGenerator.cxx

+ 7 - 8
Source/cmExportFileGenerator.cxx

@@ -985,19 +985,18 @@ void cmExportFileGenerator::GenerateExpectedTargetsCode(
   /* clang-format off */
   os << "# Protect against multiple inclusion, which would fail when already "
         "imported targets are added once more.\n"
-        "set(_cmake_targets_defined)\n"
-        "set(_cmake_targets_not_defined)\n"
-        "set(_cmake_expected_targets)\n"
+        "set(_cmake_targets_defined \"\")\n"
+        "set(_cmake_targets_not_defined \"\")\n"
+        "set(_cmake_expected_targets \"\")\n"
         "foreach(_cmake_expected_target " << expectedTargets << ")\n"
         "  list(APPEND _cmake_expected_targets ${_cmake_expected_target})\n"
-        "  if(NOT TARGET ${_cmake_expected_target})\n"
-        "    list(APPEND _cmake_targets_not_defined ${_cmake_expected_target})\n"
-        "  endif()\n"
         "  if(TARGET ${_cmake_expected_target})\n"
         "    list(APPEND _cmake_targets_defined ${_cmake_expected_target})\n"
+        "  else()\n"
+        "    list(APPEND _cmake_targets_not_defined ${_cmake_expected_target})\n"
         "  endif()\n"
         "endforeach()\n"
-        "if(\"${_cmake_targets_defined}\" STREQUAL \"${_cmake_expected_targets}\")\n"
+        "if(_cmake_targets_defined STREQUAL _cmake_expected_targets)\n"
         "  unset(_cmake_targets_defined)\n"
         "  unset(_cmake_targets_not_defined)\n"
         "  unset(_cmake_expected_targets)\n"
@@ -1005,7 +1004,7 @@ void cmExportFileGenerator::GenerateExpectedTargetsCode(
         "  cmake_policy(POP)\n"
         "  return()\n"
         "endif()\n"
-        "if(NOT \"${_cmake_targets_defined}\" STREQUAL \"\")\n"
+        "if(NOT _cmake_targets_defined STREQUAL \"\")\n"
         "  message(FATAL_ERROR \"Some (but not all) targets in this export "
         "set were already defined.\\nTargets Defined: ${_cmake_targets_defined}\\n"
         "Targets not yet defined: ${_cmake_targets_not_defined}\\n\")\n"

+ 2 - 2
Source/cmInstallGenerator.cxx

@@ -160,9 +160,9 @@ void cmInstallGenerator::AddInstallRule(
 std::string cmInstallGenerator::CreateComponentTest(
   const std::string& component, bool exclude_from_all)
 {
-  std::string result = R"("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "x)";
+  std::string result = "CMAKE_INSTALL_COMPONENT STREQUAL \"";
   result += component;
-  result += "x\"";
+  result += "\"";
   if (!exclude_from_all) {
     result += " OR NOT CMAKE_INSTALL_COMPONENT";
   }

+ 2 - 4
Source/cmScriptGenerator.cxx

@@ -52,8 +52,7 @@ static void cmScriptGeneratorEncodeConfig(const std::string& config,
 
 std::string cmScriptGenerator::CreateConfigTest(const std::string& config)
 {
-  std::string result =
-    cmStrCat("\"${", this->RuntimeConfigVariable, "}\" MATCHES \"^(");
+  std::string result = cmStrCat(this->RuntimeConfigVariable, " MATCHES \"^(");
   if (!config.empty()) {
     cmScriptGeneratorEncodeConfig(config, result);
   }
@@ -64,8 +63,7 @@ std::string cmScriptGenerator::CreateConfigTest(const std::string& config)
 std::string cmScriptGenerator::CreateConfigTest(
   std::vector<std::string> const& configs)
 {
-  std::string result =
-    cmStrCat("\"${", this->RuntimeConfigVariable, "}\" MATCHES \"^(");
+  std::string result = cmStrCat(this->RuntimeConfigVariable, " MATCHES \"^(");
   const char* sep = "";
   for (std::string const& config : configs) {
     result += sep;