C++/CLI libraries are incorrectly referenced from managed projects.
There is a minor issue in at least the latest release of CMake. Assume the following project structure:
-
Project A is a mixed mode C++/CLI project with the
COMMON_LANGUAGE_RUNTIME
set (e.g. to""
). -
Project B is a managed C# project, that has a dependency to Project A, defined by
ADD_DEPENDENCIES(ProjectB ProjectA)
.
The CMake documentation on defining Project A as a library states:
If a library does not export any symbols, it must not be declared as a SHARED library. For example, a Windows resource DLL or a managed C++/CLI DLL that exports no unmanaged symbols would need to be a MODULE library. This is because CMake expects a SHARED library to always have an associated import library on Windows.
Mixed-mode or managed C++ assemblies do not necessarily export any symbols, hence Project A must be defined as MODULE
. However when doing so, the project file created for Project B creates an invalid ProjectReference
:
<ProjectReference Include="ProjectA.vcxproj">
<Project>{...}</Project>
<Name>ProjectA</Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</ProjectReference>
This is due to an early-out in the cmGeneratorTarget::GetManagedType
method. The cmVisualStudio10TargetGenerator
outputs the ReferenceOutputAssembly
and CopyToOutputDirectory
tags, if the result of the GetManagedType
call equals cmGeneratorTarget::ManagedType::Undefined
. The GetManagedType
method, however, first checks if the type is EXECUTABLE
, STATIC_LIBRARY
or SHARED_LIBRARY
and returns Undefined
otherwise:
// Only libraries and executables can be managed targets.
if (this->GetType() > cmStateEnums::SHARED_LIBRARY) {
return ManagedType::Undefined;
}
However, MODULE_LIBRARY
states must not be omitted, as stated above.