繁体   English   中英

如何在Windows上使用CMake进行非交互式构建?

[英]How to Use CMake for Non-Interactive Build on Windows?

我想在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,从而挂起构建。

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

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

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

下面是原始命令行用法输出的片段。 请注意,那里没有记录-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.  

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

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

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

这是我创建的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM