summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmSystemTools.cxx47
-rw-r--r--Source/cmSystemTools.h4
-rw-r--r--Source/cmakemain.cxx8
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake14
-rw-r--r--Tests/RunCMake/CommandLine/print-config-dir-apple-stdout.txt1
-rw-r--r--Tests/RunCMake/CommandLine/print-config-dir-env-stdout.txt1
-rw-r--r--Tests/RunCMake/CommandLine/print-config-dir-stdout.txt1
-rw-r--r--Tests/RunCMake/CommandLine/print-config-dir-win-stdout.txt1
-rwxr-xr-xbootstrap2
9 files changed, 78 insertions, 1 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 3affef0..6e32bd9 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -86,6 +86,9 @@
#if defined(_WIN32)
# include <windows.h>
+
+# include <knownfolders.h>
+# include <shlobj.h>
// include wincrypt.h after windows.h
# include <wincrypt.h>
#else
@@ -2671,6 +2674,50 @@ std::string const& cmSystemTools::GetHTMLDoc()
return cmSystemToolsHTMLDoc;
}
+cm::optional<std::string> cmSystemTools::GetSystemConfigDirectory()
+{
+#if defined(_WIN32)
+ LPWSTR lpwstr;
+ if (FAILED(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &lpwstr))) {
+ return cm::nullopt;
+ }
+ std::wstring wstr = std::wstring(lpwstr);
+ CoTaskMemFree(lpwstr);
+ std::string config = cmsys::Encoding::ToNarrow(wstr);
+ cmSystemTools::ConvertToUnixSlashes(config);
+ return config;
+#else
+ auto config = cmSystemTools::GetEnvVar("XDG_CONFIG_HOME");
+ if (!config.has_value()) {
+ config = cmSystemTools::GetEnvVar("HOME");
+ if (config.has_value()) {
+# if defined(__APPLE__)
+ config = cmStrCat(config.value(), "/Library/Application Support");
+# else
+ config = cmStrCat(config.value(), "/.config");
+# endif
+ }
+ }
+ return config;
+#endif
+}
+
+cm::optional<std::string> cmSystemTools::GetCMakeConfigDirectory()
+{
+ auto config = cmSystemTools::GetEnvVar("CMAKE_CONFIG_DIR");
+ if (!config.has_value()) {
+ config = cmSystemTools::GetSystemConfigDirectory();
+ if (config.has_value()) {
+#if defined(_WIN32) || defined(__APPLE__)
+ config = cmStrCat(config.value(), "/CMake");
+#else
+ config = cmStrCat(config.value(), "/cmake");
+#endif
+ }
+ }
+ return config;
+}
+
std::string cmSystemTools::GetCurrentWorkingDirectory()
{
return cmSystemTools::CollapseFullPath(
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index d12ab07..00a6c70 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -524,6 +524,10 @@ public:
static std::string const& GetCMakeRoot();
static std::string const& GetHTMLDoc();
+ /** Get the CMake config directory **/
+ static cm::optional<std::string> GetSystemConfigDirectory();
+ static cm::optional<std::string> GetCMakeConfigDirectory();
+
/** Get the CWD mapped through the KWSys translation map. */
static std::string GetCurrentWorkingDirectory();
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 8462734..44d2e3e 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -17,6 +17,7 @@
#include <vector>
#include <cm/memory>
+#include <cm/optional>
#include <cmext/algorithm>
#include <cm3p/uv.h>
@@ -1071,6 +1072,13 @@ int main(int ac, char const* const* av)
if (strcmp(av[1], "-E") == 0) {
return do_command(ac, av, std::move(consoleBuf));
}
+ if (strcmp(av[1], "--print-config-dir") == 0) {
+ std::cout << cmSystemTools::ConvertToOutputPath(
+ cmSystemTools::GetCMakeConfigDirectory().value_or(
+ std::string()))
+ << std::endl;
+ return 0;
+ }
}
int ret = do_cmake(ac, av);
#ifndef CMAKE_BOOTSTRAP
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index 7a5a334..7f9b14b 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -1128,3 +1128,17 @@ if(RunCMake_GENERATOR MATCHES "^Visual Studio 12 2013")
endif()
run_cmake_with_options(help-arbitrary "--help" "CMAKE_CXX_IGNORE_EXTENSIONS")
+
+if (WIN32 OR DEFINED ENV{HOME})
+ set(config_dir_test print-config-dir)
+ if (WIN32)
+ set(config_dir_test print-config-dir-win)
+ elseif(APPLE)
+ set(config_dir_test print-config-dir-apple)
+ endif()
+ unset(ENV{CMAKE_CONFIG_DIR})
+ unset(ENV{XDG_CONFIG_HOME})
+ run_cmake_command(${config_dir_test} ${CMAKE_COMMAND} "--print-config-dir")
+endif()
+set(ENV{CMAKE_CONFIG_DIR} cmake_config_dir)
+run_cmake_command(print-config-dir-env ${CMAKE_COMMAND} "--print-config-dir")
diff --git a/Tests/RunCMake/CommandLine/print-config-dir-apple-stdout.txt b/Tests/RunCMake/CommandLine/print-config-dir-apple-stdout.txt
new file mode 100644
index 0000000..59db482
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/print-config-dir-apple-stdout.txt
@@ -0,0 +1 @@
+.*Library/Application\\ Support/CMake$
diff --git a/Tests/RunCMake/CommandLine/print-config-dir-env-stdout.txt b/Tests/RunCMake/CommandLine/print-config-dir-env-stdout.txt
new file mode 100644
index 0000000..49f1d7b
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/print-config-dir-env-stdout.txt
@@ -0,0 +1 @@
+cmake_config_dir
diff --git a/Tests/RunCMake/CommandLine/print-config-dir-stdout.txt b/Tests/RunCMake/CommandLine/print-config-dir-stdout.txt
new file mode 100644
index 0000000..53f6c8b
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/print-config-dir-stdout.txt
@@ -0,0 +1 @@
+.*config/cmake$
diff --git a/Tests/RunCMake/CommandLine/print-config-dir-win-stdout.txt b/Tests/RunCMake/CommandLine/print-config-dir-win-stdout.txt
new file mode 100644
index 0000000..9df0671
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/print-config-dir-win-stdout.txt
@@ -0,0 +1 @@
+.*AppData\\Local\\CMake$
diff --git a/bootstrap b/bootstrap
index 49b91d5..841d280 100755
--- a/bootstrap
+++ b/bootstrap
@@ -1763,7 +1763,7 @@ libs=""
uv_c_flags=""
if ${cmake_system_mingw}; then
uv_c_flags="${uv_c_flags} -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600"
- libs="${libs} -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv -lole32 -loleaut32"
+ libs="${libs} -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv -lole32 -loleaut32 -luuid"
else
case "${cmake_system}" in
*AIX*)