summaryrefslogtreecommitdiffstats
path: root/Source/cmFileAPI.cxx
diff options
context:
space:
mode:
authorMartin Duffy <martin.duffy@kitware.com>2024-08-16 12:49:10 (GMT)
committerBrad King <brad.king@kitware.com>2024-08-22 14:24:23 (GMT)
commit1df94443fe5a24e43325b95d93043e8bf5565fa2 (patch)
tree8657e1e1d54ed7ccdac6b249fb09b4bc65d709c8 /Source/cmFileAPI.cxx
parenta991a5019b87ab7119b2e7b92434c8f006404519 (diff)
downloadCMake-1df94443fe5a24e43325b95d93043e8bf5565fa2.zip
CMake-1df94443fe5a24e43325b95d93043e8bf5565fa2.tar.gz
CMake-1df94443fe5a24e43325b95d93043e8bf5565fa2.tar.bz2
fileapi: Add support for user-wide queries
Fixes: #19168
Diffstat (limited to 'Source/cmFileAPI.cxx')
-rw-r--r--Source/cmFileAPI.cxx23
1 files changed, 21 insertions, 2 deletions
diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx
index d4a7175..1f15612 100644
--- a/Source/cmFileAPI.cxx
+++ b/Source/cmFileAPI.cxx
@@ -7,9 +7,13 @@
#include <chrono>
#include <ctime>
#include <iomanip>
+#include <iterator>
#include <sstream>
#include <utility>
+#include <cm/optional>
+#include <cmext/string_view>
+
#include "cmsys/Directory.hxx"
#include "cmsys/FStream.hxx"
@@ -29,7 +33,12 @@ cmFileAPI::cmFileAPI(cmake* cm)
: CMakeInstance(cm)
{
this->APIv1 =
- this->CMakeInstance->GetHomeOutputDirectory() + "/.cmake/api/v1";
+ cmStrCat(this->CMakeInstance->GetHomeOutputDirectory(), "/.cmake/api/v1");
+
+ if (cm::optional<std::string> cmakeConfigDir =
+ cmSystemTools::GetCMakeConfigDirectory()) {
+ this->UserAPIv1 = cmStrCat(std::move(*cmakeConfigDir), "/api/v1"_s);
+ }
Json::CharReaderBuilder rbuilder;
rbuilder["collectComments"] = false;
@@ -47,14 +56,24 @@ cmFileAPI::cmFileAPI(cmake* cm)
void cmFileAPI::ReadQueries()
{
- std::string const query_dir = this->APIv1 + "/query";
+ std::string const query_dir = cmStrCat(this->APIv1, "/query");
+ std::string const user_query_dir = cmStrCat(this->UserAPIv1, "/query");
this->QueryExists = cmSystemTools::FileIsDirectory(query_dir);
+ if (!this->UserAPIv1.empty()) {
+ this->QueryExists =
+ this->QueryExists || cmSystemTools::FileIsDirectory(user_query_dir);
+ }
if (!this->QueryExists) {
return;
}
// Load queries at the top level.
std::vector<std::string> queries = cmFileAPI::LoadDir(query_dir);
+ if (!this->UserAPIv1.empty()) {
+ std::vector<std::string> user_queries = cmFileAPI::LoadDir(user_query_dir);
+ std::move(user_queries.begin(), user_queries.end(),
+ std::back_inserter(queries));
+ }
// Read the queries and save for later.
for (std::string& query : queries) {