2

I have a CMake project that should not be built in 32-bit mode on x86, and I can't for the life of me figure out how to prevent that from happening.

Right now, it appears cmake <path>, by default on windows assumes a 32-bit build.

How can I make my CMake project always build the 64-bit variant, without requiring the passing of command-line arguments to CMake?

Alternatively, how can I make CMake abort if it is trying to be built as 32-bit?

Vertexwahn
  • 7,129
  • 6
  • 55
  • 83
Fake Name
  • 5,156
  • 4
  • 42
  • 63
  • There is no generic/cross-platform method to enforce 64bit builds. This is normally something the user of your project can decide. For the VS part see ["How to detect if 64 bit MSVC with cmake?"](https://stackoverflow.com/questions/39258250/how-to-detect-if-64-bit-msvc-with-cmake) – Florian Feb 01 '18 at 08:27

1 Answers1

1

You can add to our CMakeLists.txt the following code to ensure that only x64 builds are allowed:

if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
    message("Please switch to x64 build.")
    return()
endif()
Vertexwahn
  • 7,129
  • 6
  • 55
  • 83