From ddf7ebe06e937a4a242a0bca19d58a136e40e471 Mon Sep 17 00:00:00 2001 From: Nikita Nemkin Date: Fri, 7 Feb 2025 15:00:52 +0500 Subject: [PATCH] cmake: Friendlier message when trying to --build the wrong dir Also for --open. Fixes: #11166 --- Source/cmake.cxx | 6 ++++-- .../CommandLine/build-invalid-target-syntax-stderr.txt | 2 +- Tests/RunCMake/CommandLine/build-no-cache-stderr.txt | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 20551679ac..1420cb683a 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -3850,7 +3850,8 @@ int cmake::Build(int jobs, std::string dir, std::vector 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"); diff --git a/Tests/RunCMake/CommandLine/build-invalid-target-syntax-stderr.txt b/Tests/RunCMake/CommandLine/build-invalid-target-syntax-stderr.txt index fa3adc8743..1eebfc603f 100644 --- a/Tests/RunCMake/CommandLine/build-invalid-target-syntax-stderr.txt +++ b/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\)$ diff --git a/Tests/RunCMake/CommandLine/build-no-cache-stderr.txt b/Tests/RunCMake/CommandLine/build-no-cache-stderr.txt index 40dd3c0979..1eebfc603f 100644 --- a/Tests/RunCMake/CommandLine/build-no-cache-stderr.txt +++ b/Tests/RunCMake/CommandLine/build-no-cache-stderr.txt @@ -1 +1 @@ -^Error: could not load cache$ +^Error: not a CMake build directory \(missing CMakeCache\.txt\)$