Windows 中 CMake 的默认生成器是什么? [英] What is the default generator for CMake in Windows?

查看:30
本文介绍了Windows 中 CMake 的默认生成器是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一台 PC 上运行 CMake 时,CMake 默认生成 NMake 文件.另一方面,它生成一个 Visual Studio 项目.

When running CMake on one PC, CMake generates NMake files by default. On another, it generates a Visual Studio project.

我知道我可以通过在 CMake 语句的末尾添加 -G "NMake Makefiles" 来覆盖默认值,但我想知道为什么它默认为一个和 NMake 文件上的 Visual Studio 项目在另一个.

I know I can override the default by adding -G "NMake Makefiles" to the end of my CMake statement, but I want to know why it defaults to Visual Studio projects on one and NMake files on another.

推荐答案

以下来自CMake Source(2.8.4版:cmake.cxx:起始行2039):

The following is from the CMake Source (version 2.8.4: cmake.cxx: starting line 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() << "
";

似乎 CMake 会查看 Windows 注册表以确定要使用的生成器.它会在 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\ 中的 Visual Studio 注册表子项(6.0、7.0 等)中搜索名为 InstallDir 的条目.如果找到,则使用相应的生成器.(它将使用最新版本的 Visual Studio.)否则,它将使用 NMake 生成器.

It appears that CMake looks at the Windows Registry to determine which generator to use. It searches the Visual Studio registry subkeys (6.0, 7.0, etc) in [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.

请注意,InstallDir 条目并不总是存在,即使安装了特定版本的 Visual Studio.这可能与安装设置或 Visual Studio 的特定版本有关(例如,Visual C++ 的Express"版本似乎没有添加此条目.)

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.)

当然,可以通过将 -G {Generator Name} 附加到 CMake 命令的末尾来覆盖默认设置.

It is, of course, possible to override the default setting by appending -G {Generator Name} to the end of your CMake command.

这篇关于Windows 中 CMake 的默认生成器是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆