1

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.

Kevin
  • 16,549
  • 8
  • 60
  • 74
MrD
  • 629
  • 1
  • 8
  • 22

2 Answers2

2

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")

0

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.

MrD
  • 629
  • 1
  • 8
  • 22