Build for 32 and 64 bit

Due to targeting certain features of Windows the 32 bit binaries must be generated even on a 64 bit system. What is the best way to do this? I’d like to have it happen with one build system invocation, but am unsure of what is normally done.

I’m running under MSYS2 and would prefer to use the MinGW compiler toolchains.

@ben.boeckel I think cmake would benefit from explicit documentation on building 32/64-bit binaries.

Because I’ve seen this same question asked many times now on stackoverflow and this discourse website.
It seems to be a topic of confusion for many new cmake developers.

I’ve found a few ways to do it but it seems to depend on toolchain. In my case, ninja doesn’t seem to support specifying a bitness for the target, and running cmake under the 32 bit MSYS2 shell produces ninja build files that try to use the 64 bit toolchain.

Agreed. I’m not sure of the best place to put it within the docs (the tutorial? with the generator at hand?), but please open an issue about it (links to questions and/or experiences would be helpful).

Do you mean the 64-bit-generating toolchain or a toolchain that is itself compiled as 64bit binaries? I think MSYS2 might need -m32 or something to make it compile 32-bit. Though I’ve not done so in years, so my memory may be flaky here.