CMake - Building C# without Prefer 32-bit Flag

763 Views Asked by At

I have a CMake project that creates a DLL from C++ and a C# Windows Forms executable that loads the DLL.

I use the CMake generator: Visual Studio 15 2017 Win64

No matter what I do (one example would be setting compile option: /platform:anycpu), I cannot get CMake to not have the compile flag: /platform:anycpu32bitpreferred.

When I opened up the generated VS project in VS2017, it has the "Prefer 32-bit" flag set in the build options.

Is there any way to force CMake to generate my C# project without this flag set? It is causing run-time linking issues unless I use a 32-bit DLL.

2

There are 2 best solutions below

0
MrD On

This problem looks to be part of a bigger issue in CMake: https://gitlab.kitware.com/cmake/cmake/issues/17521

I have found a workaround, which is to set the following environment variable before building:

set Prefer32Bit=false

However, the draw back is that this is set for the entire build, and not per-project.

0
Victor Kovrevsky On

This works for me. Tested on cmake 3.14, but should work for 3.8.2 and up.

set_property(TARGET ${TARGET_NAME} PROPERTY VS_GLOBAL_Prefer32Bit "false")