summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-08-26 13:48:20 (GMT)
committerKitware Robot <kwrobot@kitware.com>2024-08-26 13:48:40 (GMT)
commitfe63f15383fec54f08eb469a26a23aaa2b10d403 (patch)
treeab2d39c0da4d1298718275d3d6f2520d1ab90f41
parentb448d7cc3a21f3ddb4e06f3784fbd68bd95972d7 (diff)
parent1df94443fe5a24e43325b95d93043e8bf5565fa2 (diff)
downloadCMake-fe63f15383fec54f08eb469a26a23aaa2b10d403.zip
CMake-fe63f15383fec54f08eb469a26a23aaa2b10d403.tar.gz
CMake-fe63f15383fec54f08eb469a26a23aaa2b10d403.tar.bz2
Merge topic 'fileapi-config-dir'
1df94443fe fileapi: Add support for user-wide queries a991a5019b Tests: Isolate test suite from user-wide configuration 320b81847d Tests: Remove unused cvs anonymous access credentials Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !9744
-rw-r--r--Help/envvar/CMAKE_CONFIG_DIR.rst18
-rw-r--r--Help/manual/cmake-env-variables.7.rst3
-rw-r--r--Help/manual/cmake-file-api.7.rst4
-rw-r--r--Help/manual/cmake.1.rst8
-rw-r--r--Source/cmFileAPI.cxx23
-rw-r--r--Source/cmFileAPI.h3
-rw-r--r--Source/cmakemain.cxx4
-rw-r--r--Tests/CMakeLists.txt9
-rw-r--r--Tests/EnforceConfig.cmake.in1
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/ConfigDir/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/ConfigDir/RunCMakeTest.cmake6
-rw-r--r--Tests/RunCMake/ConfigDir/check-reply.cmake3
-rw-r--r--Tests/RunCMake/ConfigDir/config.cmake0
-rw-r--r--Tests/RunCMake/ConfigDir/config/api/v1/query/codemodel-v20
15 files changed, 79 insertions, 7 deletions
diff --git a/Help/envvar/CMAKE_CONFIG_DIR.rst b/Help/envvar/CMAKE_CONFIG_DIR.rst
new file mode 100644
index 0000000..1b5f14f
--- /dev/null
+++ b/Help/envvar/CMAKE_CONFIG_DIR.rst
@@ -0,0 +1,18 @@
+CMAKE_CONFIG_DIR
+----------------
+
+.. versionadded:: 3.31
+
+.. include:: ENV_VAR.txt
+
+Specify a CMake user-wide configuration directory for
+:manual:`cmake-file-api(7)` queries.
+
+If this environment variable is not set, the default user-wide
+configuration directory is platform-specific:
+
+- Windows: ``%LOCALAPPDATA%\CMake``
+- macOS: ``$XDG_CONFIG_HOME/CMake`` if set, otherwise
+ ``$HOME/Library/Application Support/CMake``
+- Linux/Other: ``$XDG_CONFIG_HOME/cmake`` if set, otherwise
+ ``$HOME/.config/cmake``
diff --git a/Help/manual/cmake-env-variables.7.rst b/Help/manual/cmake-env-variables.7.rst
index 68ee79a..b2ceeae 100644
--- a/Help/manual/cmake-env-variables.7.rst
+++ b/Help/manual/cmake-env-variables.7.rst
@@ -43,8 +43,9 @@ Environment Variables that Control the Build
/envvar/CMAKE_BUILD_PARALLEL_LEVEL
/envvar/CMAKE_BUILD_TYPE
/envvar/CMAKE_COLOR_DIAGNOSTICS
- /envvar/CMAKE_CONFIGURATION_TYPES
+ /envvar/CMAKE_CONFIG_DIR
/envvar/CMAKE_CONFIG_TYPE
+ /envvar/CMAKE_CONFIGURATION_TYPES
/envvar/CMAKE_CROSSCOMPILING_EMULATOR
/envvar/CMAKE_EXPORT_COMPILE_COMMANDS
/envvar/CMAKE_GENERATOR
diff --git a/Help/manual/cmake-file-api.7.rst b/Help/manual/cmake-file-api.7.rst
index 260030e..a4ce5de 100644
--- a/Help/manual/cmake-file-api.7.rst
+++ b/Help/manual/cmake-file-api.7.rst
@@ -50,6 +50,10 @@ It has the following subdirectories:
Clients may optionally create the ``reply/`` directory at any time
and monitor it for the appearance of a new reply index file.
+.. versionadded:: 3.31
+ Users can add query files to ``api/v1/query`` inside the
+ :envvar:`CMAKE_CONFIG_DIR` to create user-wide queries for all CMake projects.
+
v1 Shared Stateless Query Files
-------------------------------
diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst
index 794ef96..586a72e 100644
--- a/Help/manual/cmake.1.rst
+++ b/Help/manual/cmake.1.rst
@@ -266,6 +266,14 @@ Options
from the top of a binary tree for a CMake project it will dump
additional information such as the cache, log files etc.
+.. option:: --print-config-dir
+
+ .. versionadded:: 3.31
+
+ Print CMake config directory for user-wide FileAPI queries.
+
+ See :envvar:`CMAKE_CONFIG_DIR` for more details.
+
.. option:: --log-level=<level>
.. versionadded:: 3.16
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) {
diff --git a/Source/cmFileAPI.h b/Source/cmFileAPI.h
index 1c13d7b..ace19ee 100644
--- a/Source/cmFileAPI.h
+++ b/Source/cmFileAPI.h
@@ -61,6 +61,9 @@ private:
/** The api/v1 directory location. */
std::string APIv1;
+ /** api/v1 directory in the user's shared CMake config directory. */
+ std::string UserAPIv1;
+
/** The set of files we have just written to the reply directory. */
std::unordered_set<std::string> ReplyFiles;
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index bb80204..804f5ef 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -71,7 +71,7 @@ const cmDocumentationEntry cmDocumentationUsageNote = {
"Run 'cmake --help' for more information."
};
-const cmDocumentationEntry cmDocumentationOptions[33] = {
+const cmDocumentationEntry cmDocumentationOptions[34] = {
{ "--preset <preset>,--preset=<preset>", "Specify a configure preset." },
{ "--list-presets[=<type>]", "List available presets." },
{ "--workflow [<options>]", "Run a workflow preset." },
@@ -94,6 +94,8 @@ const cmDocumentationEntry cmDocumentationOptions[33] = {
"Generate graphviz of dependencies, see CMakeGraphVizOptions.cmake for "
"more." },
{ "--system-information [file]", "Dump information about this system." },
+ { "--print-config-dir",
+ "Print CMake config directory for user-wide FileAPI queries." },
{ "--log-level=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE>",
"Set the verbosity of messages from CMake files. "
"--loglevel is also accepted for backward compatibility reasons." },
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index dcb5d4c..a3a7589 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -32,11 +32,14 @@ endmacro()
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckSwift.cmake)
+# Isolate tests from user-wide configuration.
+set(TEST_HOME "${CMake_BINARY_DIR}/Tests/CMakeFiles/TestHome")
+set(TEST_CONFIG_ENV_CODE "# Isolate tests from user-wide configuration.
+set(ENV{CMAKE_CONFIG_DIR} \"${TEST_HOME}/.config/cmake\")\n")
+file(MAKE_DIRECTORY "${TEST_HOME}/.config/cmake")
+
# Fake a user home directory to avoid polluting the real one.
if(NOT CTEST_NO_TEST_HOME AND (NOT WIN32 OR DEFINED ENV{HOME}))
- set(TEST_HOME "${CMake_BINARY_DIR}/Tests/CMakeFiles/TestHome")
- file(MAKE_DIRECTORY "${TEST_HOME}")
- file(WRITE "${TEST_HOME}/.cvspass" ":pserver:anoncvs@www.cmake.org:/cvsroot/KWSys A\n")
set(TEST_HOME_ENV_CODE "# Fake a user home directory to avoid polluting the real one.
# But provide original ENV{HOME} value in ENV{CTEST_REAL_HOME} for tests that
# need access to the real HOME directory.
diff --git a/Tests/EnforceConfig.cmake.in b/Tests/EnforceConfig.cmake.in
index a652efc..f151dfd 100644
--- a/Tests/EnforceConfig.cmake.in
+++ b/Tests/EnforceConfig.cmake.in
@@ -38,5 +38,6 @@ unset(ENV{CMAKE_EXPORT_COMPILE_COMMANDS})
# Verify that our module implementations do not recurse too much.
set(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH} 100)
+@TEST_CONFIG_ENV_CODE@
@TEST_HOME_ENV_CODE@
@TEST_WARN_VS_CODE@
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 112e530..1f7b8c5 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -409,6 +409,7 @@ if(CMAKE_USE_SYSTEM_JSONCPP)
endif()
add_RunCMake_test(FileAPI -DPython_EXECUTABLE=${Python_EXECUTABLE}
-DCMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID})
+add_RunCMake_test(ConfigDir)
add_RunCMake_test(FindBoost)
add_RunCMake_test(FindLua)
add_RunCMake_test(FindOpenGL)
diff --git a/Tests/RunCMake/ConfigDir/CMakeLists.txt b/Tests/RunCMake/ConfigDir/CMakeLists.txt
new file mode 100644
index 0000000..dda37d8
--- /dev/null
+++ b/Tests/RunCMake/ConfigDir/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.30)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/ConfigDir/RunCMakeTest.cmake b/Tests/RunCMake/ConfigDir/RunCMakeTest.cmake
new file mode 100644
index 0000000..e5df208
--- /dev/null
+++ b/Tests/RunCMake/ConfigDir/RunCMakeTest.cmake
@@ -0,0 +1,6 @@
+include(RunCMake)
+
+set(ENV{CMAKE_CONFIG_DIR} ${CMAKE_CURRENT_LIST_DIR}/config)
+set(RunCMake-check-file check-reply.cmake)
+run_cmake(config)
+unset(RunCMake-check-file)
diff --git a/Tests/RunCMake/ConfigDir/check-reply.cmake b/Tests/RunCMake/ConfigDir/check-reply.cmake
new file mode 100644
index 0000000..6e0ecf9
--- /dev/null
+++ b/Tests/RunCMake/ConfigDir/check-reply.cmake
@@ -0,0 +1,3 @@
+if (NOT EXISTS ${RunCMake_TEST_BINARY_DIR}/.cmake/api/v1/reply)
+ set(RunCMake_TEST_FAILED "Failed to read FileAPI query from user config directory")
+endif()
diff --git a/Tests/RunCMake/ConfigDir/config.cmake b/Tests/RunCMake/ConfigDir/config.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/ConfigDir/config.cmake
diff --git a/Tests/RunCMake/ConfigDir/config/api/v1/query/codemodel-v2 b/Tests/RunCMake/ConfigDir/config/api/v1/query/codemodel-v2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/ConfigDir/config/api/v1/query/codemodel-v2