CMakePresets.json: Rework how --preset argument is handled

If a path argument with no -S or -B leads to a cache directory,
use that directory as the binary directory. Otherwise, use the
binary directory from the preset.

Fixes: #21311
This commit is contained in:
Kyle Edwards
2020-10-23 12:37:06 -04:00
committed by Craig Scott
parent f2a59d400e
commit b7d7eca66d
15 changed files with 65 additions and 32 deletions
+1 -2
View File
@@ -32,8 +32,7 @@ static const char* cmDocumentationUsage[][2] = {
" cmake-gui [options]\n"
" cmake-gui [options] <path-to-source>\n"
" cmake-gui [options] <path-to-existing-build>\n"
" cmake-gui [options] -S <path-to-source> -B <path-to-build>\n"
" cmake-gui [options] -S <path-to-source> --preset=<preset-name>\n" },
" cmake-gui [options] -S <path-to-source> -B <path-to-build>\n" },
{ nullptr, nullptr }
};
+1
View File
@@ -162,6 +162,7 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal,
cmSystemTools::Error(message.str());
}
}
this->CacheLoaded = true;
return true;
}
+4
View File
@@ -66,6 +66,9 @@ public:
//! Print the cache to a stream
void PrintCache(std::ostream&) const;
//! Get whether or not cache is loaded
bool IsCacheLoaded() const { return this->CacheLoaded; }
//! Get a value from the cache given a key
cmProp GetInitializedCacheValue(const std::string& key) const;
@@ -204,6 +207,7 @@ private:
const CacheEntry& e, cmMessenger* messenger) const;
std::map<std::string, CacheEntry> Cache;
bool CacheLoaded = false;
// Cache version info
unsigned int CacheMajorVersion = 0;
+5
View File
@@ -135,6 +135,11 @@ bool cmState::DeleteCache(const std::string& path)
return this->CacheManager->DeleteCache(path);
}
bool cmState::IsCacheLoaded() const
{
return this->CacheManager->IsCacheLoaded();
}
std::vector<std::string> cmState::GetCacheEntryKeys() const
{
return this->CacheManager->GetCacheEntryKeys();
+2
View File
@@ -87,6 +87,8 @@ public:
bool DeleteCache(const std::string& path);
bool IsCacheLoaded() const;
std::vector<std::string> GetCacheEntryKeys() const;
cmProp GetCacheEntryValue(std::string const& key) const;
std::string GetSafeCacheEntryValue(std::string const& key) const;
+3 -1
View File
@@ -727,6 +727,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
{
bool haveToolset = false;
bool havePlatform = false;
bool haveBArg = false;
#if !defined(CMAKE_BOOTSTRAP)
std::string profilingFormat;
std::string profilingOutput;
@@ -775,6 +776,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
path = cmSystemTools::CollapseFullPath(path);
cmSystemTools::ConvertToUnixSlashes(path);
this->SetHomeOutputDirectory(path);
haveBArg = true;
} else if ((i < args.size() - 2) &&
cmHasLiteralPrefix(arg, "--check-build-system")) {
this->CheckBuildSystemArgument = args[++i];
@@ -1057,7 +1059,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
return;
}
if (!haveBinaryDir) {
if (!this->State->IsCacheLoaded() && !haveBArg) {
this->SetHomeOutputDirectory(expandedPreset->BinaryDir);
}
if (!this->GlobalGenerator) {
+1 -2
View File
@@ -49,8 +49,7 @@ const char* cmDocumentationUsage[][2] = {
{ nullptr,
" cmake [options] <path-to-source>\n"
" cmake [options] <path-to-existing-build>\n"
" cmake [options] -S <path-to-source> -B <path-to-build>\n"
" cmake [options] -S <path-to-source> --preset=<preset-name>" },
" cmake [options] -S <path-to-source> -B <path-to-build>" },
{ nullptr,
"Specify a source directory to (re-)generate a build system for "
"it in the current working directory. Specify an existing build "