<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 27, 2017 at 7:04 PM, LightGoLeft <span dir="ltr"><<a href="mailto:drakedog2008@outlook.com" target="_blank">drakedog2008@outlook.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
I am currently using TDM-GCC-64 (MinGW) and MSVC to build binaries on 64 bit<br>
Windows to build both 32 and 64bit binaries. However, I found architecture<br>
passed to GNUtoMS bat is determined by CMAKE_SIZEOF_VOID_P which is not<br>
correctly set.<br>
<br>
For GCC, I set<br>
  SET(CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")<br>
  SET(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")<br>
But, message(${CMAKE_SIZEOF_VOID_P }) is always 8. That causes GNUtoMS<br>
generating x64 *.lib from x86 *.a. I don't know whether this is a bug or by<br>
design.<br></blockquote><div><br></div><div>CMake determines the bitness of the target when it does its compiler checks, which is performed at the first project() command it hits, and it caches the result for all subsequent CMake invocations. If you need to pass a flag like -m32 to build for 32-bit targets on a 64-bit host, you need to use a toolchain file and specify the -m32 option in there. If you simply add lines like your example above to your project's CMakeLists.txt file, they won't be picked up properly when CMake does its compiler tests. The correct way to specify this sort of flag in a toolchain file would look something like this (note the use of ..._INIT variables):</div><div><br></div><div><div><span style="font-family:monospace,monospace">set(CMAKE_C_FLAGS_INIT   -m32)</span><br></div><div><font face="monospace, monospace">set(CMAKE_CXX_FLAGS_INIT -m32)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">set(CMAKE_EXE_LINKER_FLAGS_INIT    -m32)</font></div><div><font face="monospace, monospace">set(CMAKE_MODULE_LINKER_FLAGS_INIT -m32)</font></div><div><font face="monospace, monospace">set(CMAKE_SHARED_LINKER_FLAGS_INIT -m32)</font></div></div><div><br></div><div>Your toolchain file should also be setting CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_VERSION and CMAKE_SYSTEM_PROCESSOR to whatever is appropriate for your target architecture/platform (sorry, I'm not sure off the top of my head what these would typically be for your case). Be sure to clear any previous build if you want to experiment with this, since CMake caches its results after the first run.</div></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div></div></div></div></div></div></div>
</div></div>