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

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

问题描述

让 cmake 使用 Visual Studio 在 Windows 上构建 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 使用 Visual Studio 在 Windows 上构建 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.

要在不启动 Visual Studio 命令提示符的情况下从命令行为 32 位和 64 位构建 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 versions 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 option specifies the build configuration.

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

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