Chr*_*ley 18 c nmake generator cmake visual-studio
在一台PC上运行CMake时,CMake默认生成NMake文件.另一方面,它生成一个Visual Studio项目.
我知道我可以通过添加-G "NMake Makefiles"到我的CMake语句的末尾来覆盖默认值,但我想知道为什么它默认为一个上的Visual Studio项目和另一个上的NMake文件.
Chr*_*ley 17
以下内容来自CMake Source(版本2.8.4:cmake.cxx:起始行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";
Run Code Online (Sandbox Code Playgroud)
似乎CMake查看Windows注册表以确定要使用哪个生成器.它在Visual Studio注册表子项(6.0,7.0等)中[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\搜索名为的条目InstallDir.如果找到一个,它使用相应的生成器.(它将使用最新版本的Visual Studio.)否则,它使用NMake生成器.
请注意InstallDir,即使安装了特定版本的Visual Studio ,该条目也不会始终存在.这可能与安装设置或特定版本的Visual Studio有关(例如,似乎Visual C++的"Express"版本不会添加此条目.)
当然,可以通过附加-G {Generator Name}到CMake命令的末尾来覆盖默认设置.
| 归档时间: |
|
| 查看次数: |
13458 次 |
| 最近记录: |