【问题标题】:How to Use CMake for Non-Interactive Build on Windows?如何在 Windows 上使用 CMake 进行非交互式构建?
【发布时间】:2010-11-30 09:02:46
【问题描述】:

我想在 Windows 上使用 CMake 设置自动构建。我正在使用 Visual Studio 2005。

更新:这是我正在使用的:

我将 devenv.exe 设置为我的 PATH。然后构建我运行下面的命令。我正在使用 Hudson 构建。

devenv Crackpot.sln /build Debug /project ALL_BUILD

根据http://blogs.msdn.com/aaronhallberg/archive/2007/06/29/building-from-the-command-line-with-devenv.aspx,更喜欢使用“devenv”而不是“denenv.exe”,因为后者可能会产生一个 GUI,从而挂起构建。

【问题讨论】:

  • 你能把问题说得更具体一点吗?我不清楚您希望从社区中看到什么。
  • @Adriaan 我的意思是在运行“cmake -G”以生成 Visual Studio 项目文件之后运行什么。抱歉,您显然不清楚。
  • 为了后代:通常的方法是使用“NMake Makefiles”生成器并运行nmake。这里使用的是微软自己的nmake,这是make的Windows版本。
  • 使用 msbuild 代替 devenv

标签: windows build cmake


【解决方案1】:

我发现最简单的方法是:
% cmake --build "buildDir"
你也可以添加--target --config 'Debug|Release|...'

【讨论】:

  • 这实际上是该线程中最有用的答案,也是唯一真正回答问题的答案。这允许任何在非 Visual Studio 外壳中运行 cmake 的人构建所有内容,包括例如“安装”目标。
【解决方案2】:

您可以从命令行运行 CMake。 你可以跑了。

cmake.exe -G"Visual Studio 8 2005" -H<source_dir> -B<build_dir>

下面是来自原始命令行使用输出的 sn-p。 请注意,那里没有记录 -H 和 -B 选项。但它们可用于在命令行上显式定义源目录和构建目录。

C:\Program Files (x86)\CMake 2.6\bin>cmake
  cmake version 2.6-patch 4
  Usage

  cmake [options] <path-to-source>
  cmake [options] <path-to-existing-build>

  Options
  -C <initial-cache>          = Pre-load a script to populate the cache.
  -D <var>:<type>=<value>     = Create a cmake cache entry.
  -U <globbing_expr>          = Remove matching entries from CMake cache.
  -G <generator-name>         = Specify a makefile generator.
  -Wno-dev                    = Suppress developer warnings.
  -Wdev                       = Enable developer warnings.
  -E                          = CMake command mode.
  -i                          = Run in wizard mode.
  -L[A][H]                    = List non-advanced cached variables.
  -N                          = View mode only.
  -P <file>                   = Process script mode.

这里是可用的生成器。

Generators

The following generators are available on this platform:
  Borland Makefiles           = Generates Borland makefiles.
  MSYS Makefiles              = Generates MSYS makefiles.
  MinGW Makefiles             = Generates a make file for use with
                                mingw32-make.
  NMake Makefiles             = Generates NMake makefiles.
  Unix Makefiles              = Generates standard UNIX makefiles.
  Visual Studio 6             = Generates Visual Studio 6 project files.
  Visual Studio 7             = Generates Visual Studio .NET 2002 project
                                files.
  Visual Studio 7 .NET 2003   = Generates Visual Studio .NET 2003 project
                                files.
  Visual Studio 8 2005        = Generates Visual Studio .NET 2005 project
                                files.
  Visual Studio 8 2005 Win64  = Generates Visual Studio .NET 2005 Win64
                                project files.
  Visual Studio 9 2008        = Generates Visual Studio 9 2008 project files.
  Visual Studio 9 2008 Win64  = Generates Visual Studio 9 2008 Win64 project
                                files.
  Watcom WMake                = Generates Watcom WMake makefiles.
  CodeBlocks - MinGW Makefiles= Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
  Eclipse CDT4 - MinGW Makefiles
                              = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - NMake Makefiles
                              = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles
                              = Generates Eclipse CDT 4.0 project files.  

【讨论】:

  • 很好,虽然我希望只告诉他在命令行上运行 cmake 以查看帮助就足够了,因为您已经指定了一个有效的示例命令行:)
  • 我会给你一个 +1 的明显解决方案。现在我们只需要确定这是否是 Amit Kumar 想要的:D
  • 很抱歉没有说清楚,但是我的意思是运行cmake之后要做什么。 OregonGhost 的答案对我有用。感谢您抽出宝贵时间。
【解决方案3】:

我不确定我是否理解这个问题。您可以像使用任何其他构建系统一样使用它。只需指定“Visual Studio 8 2005”(有点奇怪,但您可以通过调用不带参数的 cmake 来获取所有支持的系统的列表),您将获得可以在命令行上使用 devenv.exe /build 或使用 MSBuild。

唯一有点复杂的是,如果您想在未安装 Visual Studio 时生成解决方案,例如在构建服务器上。当然,您可以只安装它,但我不想安装您不需要的东西。在这种情况下,您必须伪造它以接受 MSBuild 作为构建命令行(通过在命令行中指定一个批处理文件作为构建工具,这只是重新排序参数以便 MSBuild 接受它们),这样它就不会开始抱怨关于它如何错过 Visual Studio(这太疯狂了,因为 CMake 人来自命令行世界......)

哦,如果您真正想要的只是在命令行上构建现有的 Visual Studio 解决方案,那么您不需要 CMake。只需致电 MSBuild 或 devenv /build

【讨论】:

  • 是的,我正在寻找运行 cmake 后的步骤。谢谢,这很有帮助。
【解决方案4】:

这是我创建的 bat 文件。它会自动在您指定的构建文件夹中创建解决方案,每次删除并创建一个新的构建文件夹。

RMDIR C:\Users\abc /s /q

if EXIST C:\Users\abc GOTO FALIURE

MKDIR C:\Users\abc\build
CD C:\Users\abc\build
cmake -G "Visual Studio 12" "C:\Users\abc\src"
EXIT

:FALIURE
CLS
echo "Failed to delete BUILD directory, Close all related files and programs and try again."
pause
EXIT

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-02
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多