C# and C++/CLI project issues
There are several issues with the C# and C++/CLI integration in CMake, I recently had to work around.
The 'source_group' command doesn't seem to work for MSVC2017/C# projects. I just wanted to group some C# files into a folder and nothing happened, so I had a brief look into the code and found the Regex to ignore .cs files.
Sample code I've been using:
add_executable( TestProject WIN32 Frontend/main.cs Frontend/foo.cs)
source_group( Bar FILES "${CMAKE_SOURCE_DIR}/src/UI/Frontend/foo.cs" )
The studio version I'm using is VS2017, the rest of C# bindings seem to work quite well using the CSharpUtilities (project generation, reference property and stuff like that).
Some other minor things (apart from the source groups), but which could be successfully workaround otherwise:
- target_link_libraries() linking from a C# target to a native C++/CLI target doesn't seem to have effect (can be solved through setting property VS_DOTNET_REFERENCE_)
- it feels somehow weird to get different kind of binaries, when linking C# frontend against a C++/CLI subcomponent of the same project (DLL) - with default setting (no overrides), I'm getting a VS-project with x64 build on C# side and 32-bit C++...
- another thing I'm having some stomach pains are the default compiler flags for MSVC++ debug builds - when building the C++/CLI subcomponent, I needed to remove the default flags for the runtime-check-crap in Debug using regex replace:
string (REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string (REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set_source_files_properties( ${files_dotnet} PROPERTIES COMPILE_FLAGS "/Zc:twoPhase- /clr /EHa" )
Actually I truly like the C# support for CMake, in especially for defining precise deployments including C++/CLI components.