How do I determine the default bit architecture that cmake selects in windows

How do I determine the default bit architecture that cmake selects in windows?

I thought I could check the CMAKE_GENERATOR and/or CMAKE_GENERATOR_PLATFORM but this information doesn’t seem to be consistent.

For example:

If I invoke

cmake . -Bfoo -A Win32
...
-- CMAKE_GENERATOR="Visual Studio 17 2022"
-- CMAKE_GENERATOR_PLATFORM="Win32"
...
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x86/cl.exe - skipped

This works as I expected, generating a 32B solution file and prduct.


If I invoke

cmake . -Bfoo -A Win64
...
-- CMAKE_GENERATOR="Visual Studio 17 2022"
-- CMAKE_GENERATOR_PLATFORM="x64"
...
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped

this also wroks as expected, giving me a 64B solution.


However, if I do not specify a -A value the information is unexpected/inconsistatn

cmake . -Bfoo
-- CMAKE_GENERATOR="Visual Studio 17 2022"
-- CMAKE_GENERATOR_PLATFORM=""
...
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped

The CMAKE_GENERATOR_PLATFORM is unset so it’s unclear if this is 32B or 64B, but then the working C compiler check shows it’s 64B.

And I don’t see a way for my CMake file to be able to detemine what my bit architecture is in this scenario.


For my environment I have:

  • cmake version 3.23.1
  • visual studio 2015
  • visual studio 2017
  • visual studio 2019
  • visual studio 2022

Yes, 4 versions of visual studio installed.


To add more to this riddle if I run on a machine with only VS2017 installed it seems to default to a 32B compilation

cmake . -Bfoo
...
-- CMAKE_GENERATOR="Visual Studio 15 2017"
-- CMAKE_GENERATOR_PLATFORM=""
...
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped

In GitHub - McMartin/FRUT: Building JUCE projects using CMake made easy, I use

    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
      set(is_x64 TRUE)
    else()
      set(is_x64 FALSE)
    endif()