ChatGPT解决这个技术问题 Extra ChatGPT

How to build x86 and/or x64 on Windows from command line with CMAKE?

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

Start Visual Studio Command prompt for x86 Run cmake: cmake -G "NMake Makefiles" \path_to_source\ nmake

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

Start Visual Studio Command prompt for x64 Run cmake: cmake -G "NMake Makefiles" \path_to_source\ nmake

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

Same here, but there seems to be a solution: zeroset.mnim.org/2015/07/15/… (and that without closing the prompt, and using nmake)
If you arrived here because you are using -G"Ninja" as a generator on windows; to build 32bit use "x86 Native Tools Command Prompt" and to build 64bit use "x64 Native Tools Command Prompt" it will use the correct libs, compiler and linker.

s
sakra

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.

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.

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

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

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.


Is there a way to use one command prompt + two build directories, and make both architectures without having to exit and start the x86 prompt, then the x64 prompt?
Z
Zam

try use CMAKE_GENERATOR_PLATFORM

e.g.

// x86
cmake -DCMAKE_GENERATOR_PLATFORM=x86 . 

// x64
cmake -DCMAKE_GENERATOR_PLATFORM=x64 . 

simple yet portable!
use Win32 and Win64 instead of x86 and x64 for visual studio 2019
@maidamai I believe it is Win32 and x64 for VS 16 2019 stackoverflow.com/a/58548724/3554391
u
user7610

Besides CMAKE_GENERATOR_PLATFORM variable, there is also the -A switch

cmake -G "Visual Studio 16 2019" -A Win32
cmake -G "Visual Studio 16 2019" -A x64

https://cmake.org/cmake/help/v3.16/generator/Visual%20Studio%2016%202019.html#platform-selection

  -A <platform-name>           = Specify platform name if supported by
                                 generator.