Wenn CMake auf einem PC ausgeführt wird, generiert CMake standardmäßig NMake-Dateien. Zum anderen generiert es ein Visual Studio-Projekt.
Ich weiß, dass ich die Standardeinstellung durch Hinzufügen überschreiben kann -G "NMake Makefiles"
bis zum Ende meiner CMake-Anweisung, aber ich möchte wissen, warum es standardmäßig Visual Studio-Projekte auf einem und NMake-Dateien auf einem anderen verwendet.
Folgendes stammt aus der CMake-Quelle (Version 2.8.4: cmake.cxx: Startlinie 2039):
// Try to find the newest VS installed on the computer and
// use that as a default if -G is not specified
std::string vsregBase =
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\";
struct VSRegistryEntryName
{
const char* MSVersion;
const char* GeneratorName;
};
VSRegistryEntryName version[] = {
{"6.0", "Visual Studio 6"},
{"7.0", "Visual Studio 7"},
{"7.1", "Visual Studio 7 .NET 2003"},
{"8.0", "Visual Studio 8 2005"},
{"9.0", "Visual Studio 9 2008"},
{"10.0", "Visual Studio 10"},
{0, 0}};
for(int i =0; version[i].MSVersion != 0; i++)
{
std::string reg = vsregBase + version[i].MSVersion;
reg += ";InstallDir]";
cmSystemTools::ExpandRegistryValues(reg);
if (!(reg == "/registry"))
{
installedCompiler = version[i].GeneratorName;
}
}
cmGlobalGenerator* gen
= this->CreateGlobalGenerator(installedCompiler.c_str());
if(!gen)
{
gen = new cmGlobalNMakeMakefileGenerator;
}
this->SetGlobalGenerator(gen);
std::cout << "-- Building for: " << gen->GetName() << "\n";
Es scheint, dass CMake in der Windows-Registrierung nachsieht, welcher Generator verwendet werden soll. Es durchsucht die Registrierungsunterschlüssel von Visual Studio (6.0, 7.0 usw.). [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\
for an entry called InstallDir
. If one is found, it uses the corresponding generator. (It will use the newest version of Visual Studio available.) Otherwise, it uses the NMake generator.
Note that the InstallDir
entry is not always present, even when a particular version of Visual Studio is installed. This may have to do with installation settings or a particular version of Visual Studio (e.g. it seems that the “Express” versions of Visual C++ do not add this entry.)
It is, of course, possible to override the default setting by appending -G {Generator Name}
to the end of your CMake command.
For posterity.
TLDR: CMake 3.15 and above uses the environment variable CMAKE_GENERATOR
as the default generator, it’ll be used by cmake
if no -G
option provided. Or if it was an invalid generator CMake will choose its internal default generator.
CMake has introduced an environment variable CMAKE_GENERATOR
controlling the default generator in version 3.15, see this CMake 3.15 Release Notes.
And the document for the environment variable CMAKE_GENERATOR.
Ist es die gleiche Version von CMake?
– rubenvb
21. Juni 2011 um 18:47 Uhr
Ja, die Version ist 2.8.4 auf beiden Maschinen.
– Chris Finley
21. Juni 2011 um 18:57 Uhr
Ich habe tatsächlich eine Lösung gefunden, aber ich kann sie erst in sieben Stunden posten… <.<
– Chris Finley
21. Juni 2011 um 19:01 Uhr
Wahrscheinlich kannst du jetzt deine Lösung posten @chrisfinley – das sind jetzt sieben Jahre 🙂
– Benutzer2023370
28. August 2018 um 12:15 Uhr
@ user2023370 – Ha! Ich habe es später an diesem Tag gepostet … auch gut, denn ich würde mich jetzt nicht daran erinnern, wenn ich es nicht getan hätte 😉
– Chris Finley
28. August 2018 um 13:09 Uhr