如何使用CMAKE从命令行在Windows上构建x86和/或x64? [英] How to build x86 and/or x64 on Windows from command line with CMAKE?

查看:1013
本文介绍了如何使用CMAKE从命令行在Windows上构建x86和/或x64?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用cmake在Windows上使用Visual Studio构建x86的一种方法如下:

One way to get cmake to build x86 on Windows with Visual Studio is like so:

  1. 为x86启动Visual Studio命令提示符
  2. 运行cmake:cmake -G "NMake Makefiles" \path_to_source\
  3. nmake

使用cmake在Windows上使用Visual Studio构建x64的一种方法如下:

One way to get cmake to build x64 on Windows with Visual Studio is like so:

  1. 为x64启动Visual Studio命令提示符
  2. 运行cmake:cmake -G "NMake Makefiles" \path_to_source\
  3. nmake

使用Cmake,如何编译一个或两个体系结构? (例如Visual Studio如何在IDE中做到这一点)

Using Cmake, how do I compile either or both architectures? (like how Visual Studio does it from in the IDE)

推荐答案

使用CMake无法完成.您必须生成两个单独的构建文件夹.一种用于x86 NMake构建,另一种用于x64 NMake构建.您无法使用CMake生成涵盖这两种体系结构的单个Visual Studio项目.

This cannot be done with CMake. You have to generate two separate build folders. One for the x86 NMake build and one for the x64 NMake build. You cannot generate a single Visual Studio project covering both architectures with CMake either.

要从命令行为32位和64位生成Visual Studio项目而不启动Visual Studio命令提示符,请使用常规的Visual Studio生成器.

To build Visual Studio projects from the command line for both 32-bit and 64-bit without starting a Visual Studio command prompt, use the regular Visual Studio generators.

对于CMake 3.13或更高版本,运行以下命令:

For CMake 3.13 or newer, run the following commands:

cmake -G "Visual Studio 16 2019" -A Win32 -S \path_to_source\ -B "build32"
cmake -G "Visual Studio 16 2019" -A x64 -S \path_to_source\ -B "build64"
cmake --build build32 --config Release
cmake --build build64 --config Release

对于早期版本的CMake,请运行以下命令:

For earlier version of CMake, run the following commands:

mkdir build32 & pushd build32
cmake -G "Visual Studio 15 2017" \path_to_source\
popd
mkdir build64 & pushd build64
cmake -G "Visual Studio 15 2017 Win64" \path_to_source\
popd
cmake --build build32 --config Release
cmake --build build64 --config Release

使用Visual Studio生成器之一的CMake生成的项目可以使用选项--build及其后的生成目录从命令行生成. --config选项指定构建配置.

CMake generated projects that use one of the Visual Studio generators can be built from the command line with using the option --build followed by the build directory. The --config options specifies the build configuration.

这篇关于如何使用CMAKE从命令行在Windows上构建x86和/或x64?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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