mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 16:32:14 -06:00
cmSystemTools: Add CMake config directory
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
.*Library/Application\\ Support/CMake$
|
||||
@@ -0,0 +1 @@
|
||||
cmake_config_dir
|
||||
1
Tests/RunCMake/CommandLine/print-config-dir-stdout.txt
Normal file
1
Tests/RunCMake/CommandLine/print-config-dir-stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
.*config/cmake$
|
||||
@@ -0,0 +1 @@
|
||||
.*AppData\\Local\\CMake$
|
||||
@@ -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*)
|
||||
|
||||
Reference in New Issue
Block a user