mirror of
https://github.com/Kitware/CMake.git
synced 2026-11-06 05:16:58 +00:00
cmake: Find the default generator only when printing the generator list
`cmake --version` and the other documentation options build the generator documentation even when they do not print it. That evaluates the default generator, which on Windows queries the Visual Studio Setup COM API for VS 18, 17, 16 and 15 in turn and constructs the newest Visual Studio generator found. It makes `cmake --version` take about 100 ms on Windows, which is a lot for a command that tools run often to detect CMake. Only `--help` and the generator listing print generators. Evaluate them only for those requests. Fixes: #28220
This commit is contained in:
1 parent
cfb3000e9e
commit
da59d7769e
5 files changed
+22
-1
No files matched your search
@@ -207,6 +207,16 @@ bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
|
||||
}
|
||||
}
|
||||
|
||||
bool cmDocumentation::RequestsGenerators() const
|
||||
{
|
||||
return std::any_of(this->RequestedHelpItems.begin(),
|
||||
this->RequestedHelpItems.end(),
|
||||
[this](RequestedHelpItem const& rhi) {
|
||||
return rhi.HelpType == ListGenerators ||
|
||||
(rhi.HelpType == Help && this->ShowGenerators);
|
||||
});
|
||||
}
|
||||
|
||||
bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
@@ -73,6 +73,9 @@ public:
|
||||
|
||||
void SetShowGenerators(bool showGen) { this->ShowGenerators = showGen; }
|
||||
|
||||
/** Whether the requested documentation prints the generator list. */
|
||||
bool RequestsGenerators() const;
|
||||
|
||||
/** Set the program name for standard document generation. */
|
||||
void SetName(std::string const& name);
|
||||
|
||||
|
||||
@@ -237,7 +237,12 @@ int do_cmake(int ac, char const* const* av)
|
||||
std::vector<std::string> args(av, av + ac);
|
||||
hcm.SetCacheArgs(args);
|
||||
|
||||
auto generators = hcm.GetGeneratorsDocumentation();
|
||||
// Finding the default generator can query Visual Studio instances,
|
||||
// so do it only when the generator list will be printed.
|
||||
std::vector<cmDocumentationEntry> generators;
|
||||
if (doc.RequestsGenerators()) {
|
||||
generators = hcm.GetGeneratorsDocumentation();
|
||||
}
|
||||
|
||||
doc.SetName("cmake");
|
||||
doc.SetSection("Name", cmDocumentationName);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
^cmake version [0-9]
|
||||
@@ -463,6 +463,8 @@ function(run_EnvironmentGenerator)
|
||||
run_cmake_command(Envgen-ninja-multi-help ${CMAKE_COMMAND} --help)
|
||||
set(ENV{CMAKE_GENERATOR} "NoSuchGenerator")
|
||||
run_cmake_command(Envgen-bad-help ${CMAKE_COMMAND} --help)
|
||||
# --version does not print generators, so it does not evaluate them
|
||||
run_cmake_command(Envgen-bad-version ${CMAKE_COMMAND} --version)
|
||||
unset(ENV{CMAKE_GENERATOR})
|
||||
|
||||
if(RunCMake_GENERATOR MATCHES "Visual Studio")
|
||||
|
||||
Reference in new issue
Block a user