Browse Source

Avoid extra / in path to CMakeLists.txt in root directory

Richard 1 month ago
parent
commit
3f7f2368d6
1 changed files with 8 additions and 4 deletions
  1. 8 4
      Source/cmake.cxx

+ 8 - 4
Source/cmake.cxx

@@ -4509,10 +4509,14 @@ void cmake::SetCMakeListName(std::string const& name)
 
 std::string cmake::GetCMakeListFile(std::string const& dir) const
 {
-  std::string listFile = cmStrCat(dir, '/', this->CMakeListName);
-  if (this->CMakeListName.empty() ||
-      !cmSystemTools::FileExists(listFile, true)) {
-    return cmStrCat(dir, "/CMakeLists.txt");
+  cm::string_view const slash =
+    dir.empty() || dir.back() != '/' ? "/"_s : ""_s;
+  std::string listFile;
+  if (!this->CMakeListName.empty()) {
+    listFile = cmStrCat(dir, slash, this->CMakeListName);
+  }
+  if (listFile.empty() || !cmSystemTools::FileExists(listFile, true)) {
+    listFile = cmStrCat(dir, slash, "CMakeLists.txt");
   }
   return listFile;
 }