MantisBT - CMake
View Issue Details
0013016CMakeCMakepublic2012-03-05 18:322012-09-03 16:00
chris.haverkate 
Brad King 
normalminoralways
closedsuspended 
WindowsWindows 76.2
CMake 2.8.7 
 
0013016: [patch] CMake does not support setting "CompileAsManaged" attribute for Visual Studio managed C++ files.
CMake does not support setting "CompileAsManaged" attribute for Visual Studio managed C++ files with the Visual Studio 10 generator.

This is not a very "cross-platform" feature (unless Mono supports managed C++?) but it is necessary for Intellisense for managed code.
Create a shared library project with managed C++ files with the Visual Studio 10 generator, and observe the apparent inability to specify whether a file needs to be compiled as managed C++ in the generated project XML file.
The attached patch adds support for the VS_COMPILE_AS_MANAGED file property:

set_source_files_properties(file.cpp PROPERTIES VS_COMPILE_AS_MANAGED false)

I tried to copy the coding style but might not have it quite right, there wasn't much guidance on the wiki. If there is a better way to introduce these changes, I'm happy to resubmit.
No tags attached.
patch VisualStudio10GeneratorAddingCompileAsManagedForSourceFileProperties.patch (2,680) 2012-03-05 18:32
https://public.kitware.com/Bug/file/4248/VisualStudio10GeneratorAddingCompileAsManagedForSourceFileProperties.patch
Issue History
2012-03-05 18:32chris.haverkateNew Issue
2012-03-05 18:32chris.haverkateFile Added: VisualStudio10GeneratorAddingCompileAsManagedForSourceFileProperties.patch
2012-03-05 18:33chris.haverkateNote Added: 0028809
2012-03-06 08:32Brad KingNote Added: 0028812
2012-03-06 14:55chris.haverkateNote Added: 0028846
2012-03-06 15:06Brad KingNote Added: 0028847
2012-03-07 12:53chris.haverkateNote Added: 0028859
2012-03-07 13:51Brad KingNote Added: 0028860
2012-03-07 13:51Brad KingStatusnew => resolved
2012-03-07 13:51Brad KingResolutionopen => suspended
2012-03-07 13:51Brad KingAssigned To => Brad King
2012-09-03 16:00David ColeNote Added: 0030829
2012-09-03 16:00David ColeStatusresolved => closed

Notes
(0028809)
chris.haverkate   
2012-03-05 18:33   
related to 0012586
(0028812)
Brad King   
2012-03-06 08:32   
Unlike 0012586 this is just a compiler flag, no? CMake should map the /clr compile flag to the CompileAsManaged property. Try this:

  set_property(SOURCE mysrc.c PROPERTY COMPILE_FLAGS "/clr")

or for a whole target:

  set_property(TARGET mylib PROPERTY COMPILE_FLAGS "/clr")
(0028846)
chris.haverkate   
2012-03-06 14:55   
The problem stems from needing to use Visual Studio as our unit test runner. To do this we need to wrap our unit tests with a managed C++ test runner (that uses the MSTest framework) and leave the tests compiling as non-managed code.

To accomplish this, we set the project to be compiled as clr:

   set_target_properties(${projectname} PROPERTIES COMPILE_FLAGS "/clr")

and then individually set the compile preference for the unit test files:

   set_source_files_properties(file.cpp PROPERTIES VS_COMPILE_AS_MANAGED false)


I was unable to see a way to clear the "/clr" compile flag using the existing set_property()

Is there some other way to accomplish what we are trying to do using existing functionality?

Thanks.
(0028847)
Brad King   
2012-03-06 15:06   
I see there is no negative version of the /clr flag which could be added to the source file to switch it back off. Also there is no negative version of the COMPILE_FLAGS property.

One workaround is to compile the unit test sources with a separate library target (add_library) that is not managed. Then compile the test executable as managed and link to the library to get the unit tests. That way the /clr option can go in the executable target COMPILE_FLAGS property without affecting the unit test sources.

Either way the proposed VS_COMPILE_AS_MANAGED property is not complete. It will not work for the Makefile generators when running MS tools. The property will need to be generalized to map to the corresponding flags in each toolchain.
(0028859)
chris.haverkate   
2012-03-07 12:53   
I reworked our build to only set the managed files with /clr instead of setting the target with /clr then negating the files that were normal C++.

This approach seems to be working now and eliminates the need for this patch.

Thanks for the help!
(0028860)
Brad King   
2012-03-07 13:51   
Thanks for reporting back. I'm resolving this issue as "suspended" until there is someone with further need along these lines.
(0030829)
David Cole   
2012-09-03 16:00   
Closing resolved issues that have not been updated in more than 4 months.