Browse Source

cmake: Friendlier message when trying to --build the wrong dir

Also for --open.

Fixes: #11166
Nikita Nemkin 9 months ago
parent
commit
ddf7ebe06e

+ 4 - 2
Source/cmake.cxx

@@ -3850,7 +3850,8 @@ int cmake::Build(int jobs, std::string dir, std::vector<std::string> targets,
 
   std::string cachePath = FindCacheFile(dir);
   if (!this->LoadCache(cachePath)) {
-    std::cerr << "Error: could not load cache\n";
+    std::cerr
+      << "Error: not a CMake build directory (missing CMakeCache.txt)\n";
     return 1;
   }
   cmValue cachedGenerator = this->State->GetCacheEntryValue("CMAKE_GENERATOR");
@@ -3979,7 +3980,8 @@ bool cmake::Open(std::string const& dir, bool dryRun)
 
   std::string cachePath = FindCacheFile(dir);
   if (!this->LoadCache(cachePath)) {
-    std::cerr << "Error: could not load cache\n";
+    std::cerr
+      << "Error: not a CMake build directory (missing CMakeCache.txt)\n";
     return false;
   }
   cmValue genName = this->State->GetCacheEntryValue("CMAKE_GENERATOR");

+ 1 - 1
Tests/RunCMake/CommandLine/build-invalid-target-syntax-stderr.txt

@@ -1 +1 @@
-^Error: could not load cache
+^Error: not a CMake build directory \(missing CMakeCache\.txt\)$

+ 1 - 1
Tests/RunCMake/CommandLine/build-no-cache-stderr.txt

@@ -1 +1 @@
-^Error: could not load cache$
+^Error: not a CMake build directory \(missing CMakeCache\.txt\)$