Option to force either 32-bit or 64-bit build with cmake
Solution 1
For Visual Studio and per https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html
For Visual Studio Generators with VS 2005 and above this specifies the target architecture.
cmake . -DCMAKE_GENERATOR_PLATFORM=x64
Solution 2
thanks for all your inputs, but on my side i've finally chosen the -m32 hack with cmake
# cmake windows 32 bits mode bug: 32 bits link mode must be explicit (otherwise cmake will always guess a 64 bits target)
# 1- run "vcbarsall.bat x86" to setup Visual Studio build profile
# 2- "set cflags=-m32" and "set cxxflags=-m32"
# 3- let the cmake plugin "automatically" guess the target platform
Flogo
Updated on March 29, 2021Comments
-
Flogo about 3 years
I would like to offer a way that always builds my target as a 32-bit or always as 64-bit executable executable with cmake independent of the host system (Adding the "-m32" or "-m64" flag for gcc, not sure yet what to do for other compilers).
I can think of three ways to do this, which one should I use?
- an option (-DUSE32bit=true)
- a tool chain (-DCMAKE_TOOLCHAIN_FILE=64bit.toolchain)
- build types (-DCMAKE_BUILD_TYPE=release32)
In my case the forced 32-bit build will be the default and should be easy to use. A forced 64-bit build is the also useful for some cases and should not be too difficult. Using the bit width of the host system rarely makes sense for my case and I don't want to support it.
I found a related question here (The proper way of forcing a 32-bit compile using CMake) but the answers mostly discuss how it can be done at all, not how best to make it configurable.