瀏覽代碼

fileapi: Fix codemodel v2 target file name for CMP0037 OLD behavior

With CMP0037 OLD behavior, executable and library target names may
contain a slash.  Avoid constructing file names with slashes.

Fixes: #19653
Brad King 6 年之前
父節點
當前提交
9da1c33cf1
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      Source/cmFileAPICodemodel.cxx

+ 6 - 0
Source/cmFileAPICodemodel.cxx

@@ -502,6 +502,12 @@ Json::Value CodemodelConfig::DumpTarget(cmGeneratorTarget* gt,
 {
 {
   Target t(gt, this->Config);
   Target t(gt, this->Config);
   std::string prefix = "target-" + gt->GetName();
   std::string prefix = "target-" + gt->GetName();
+  for (char& c : prefix) {
+    // CMP0037 OLD behavior allows slashes in target names.  Remove them.
+    if (c == '/' || c == '\\') {
+      c = '_';
+    }
+  }
   if (!this->Config.empty()) {
   if (!this->Config.empty()) {
     prefix += "-" + this->Config;
     prefix += "-" + this->Config;
   }
   }