VS: Fix WinRT component references

WinRT components need to be referenced in a similar way that managed
code libraries are referenced.  Validate that the library reference is a
WinRT component and reference it through the project.

Add test coverage for `VS_WINRT_COMPONENT`.  While at it, fix the IOT
reference failing on Win10 SDK 17763 which doesn't include it anymore.

Fixes: #18846
This commit is contained in:
Gilles Khouzam 2019-02-01 09:40:58 -08:00 committed by Brad King
parent 6c21722adb
commit cff026dbc0
6 changed files with 54 additions and 4 deletions

View File

@ -3884,8 +3884,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0)
this->WriteDotNetReferenceCustomTags(e2, name); this->WriteDotNetReferenceCustomTags(e2, name);
// If the dependency target is not managed (compiled with /clr or // If the dependency target is not managed (compiled with /clr or
// C# target) we cannot reference it and have to set // C# target) and not a WinRT component we cannot reference it and
// 'ReferenceOutputAssembly' to false. // have to set 'ReferenceOutputAssembly' to false.
auto referenceNotManaged = auto referenceNotManaged =
dt->GetManagedType("") < cmGeneratorTarget::ManagedType::Mixed; dt->GetManagedType("") < cmGeneratorTarget::ManagedType::Mixed;
// Workaround to check for manually set /clr flags. // Workaround to check for manually set /clr flags.
@ -3902,6 +3902,12 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0)
if (referenceNotManaged && dt->GetType() == cmStateEnums::STATIC_LIBRARY) { if (referenceNotManaged && dt->GetType() == cmStateEnums::STATIC_LIBRARY) {
referenceNotManaged = !dt->IsCSharpOnly(); referenceNotManaged = !dt->IsCSharpOnly();
} }
// Referencing WinRT components is okay.
if (referenceNotManaged) {
referenceNotManaged = !dt->GetPropertyAsBool("VS_WINRT_COMPONENT");
}
if (referenceNotManaged) { if (referenceNotManaged) {
e2.Element("ReferenceOutputAssembly", "false"); e2.Element("ReferenceOutputAssembly", "false");
e2.Element("CopyToOutputDirectory", "Never"); e2.Element("CopyToOutputDirectory", "Never");

View File

@ -8,6 +8,8 @@ elseif(MSVC_VERSION GREATER 1600)
set(COMPILER_VERSION "11") set(COMPILER_VERSION "11")
endif() endif()
add_subdirectory(WinRT)
set (APP_MANIFEST_NAME Package.appxmanifest) set (APP_MANIFEST_NAME Package.appxmanifest)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsPhone") if("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsPhone")
set(PLATFORM WP) set(PLATFORM WP)
@ -149,5 +151,4 @@ if("${SHORT_VERSION}" STREQUAL "10.0")
set_property(TARGET ${EXE_NAME} PROPERTY VS_SDK_REFERENCES "Microsoft.UniversalCRT.Debug, Version=${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") set_property(TARGET ${EXE_NAME} PROPERTY VS_SDK_REFERENCES "Microsoft.UniversalCRT.Debug, Version=${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif() endif()
target_link_libraries(${EXE_NAME} d3d11 JusticeLeagueWinRT)
target_link_libraries(${EXE_NAME} d3d11)

View File

@ -6,11 +6,15 @@ using namespace DirectX;
using namespace Microsoft::WRL; using namespace Microsoft::WRL;
using namespace Windows::Foundation; using namespace Windows::Foundation;
using namespace Windows::UI::Core; using namespace Windows::UI::Core;
using namespace JusticeLeagueWinRT;
CubeRenderer::CubeRenderer() CubeRenderer::CubeRenderer()
: m_loadingComplete(false) : m_loadingComplete(false)
, m_indexCount(0) , m_indexCount(0)
{ {
// Create a new WinRT object to validate that we can link properly
Batman ^ hero = ref new Batman();
hero->savePeople();
} }
void CubeRenderer::CreateDeviceResources() void CubeRenderer::CreateDeviceResources()

View File

@ -0,0 +1,14 @@
#include "Batman.h"
using namespace JusticeLeagueWinRT;
using namespace Platform;
Batman::Batman()
{
}
void Batman::savePeople()
{
int i = 0;
i++;
}

View File

@ -0,0 +1,12 @@
#pragma once
namespace JusticeLeagueWinRT {
public
ref class Batman sealed
{
public:
Batman();
void savePeople();
};
}

View File

@ -0,0 +1,13 @@
project(JusticeLeagueWinRT CXX)
# create project
add_library(JusticeLeagueWinRT SHARED
"${CMAKE_CURRENT_SOURCE_DIR}/Batman.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Batman.h"
)
set_target_properties(JusticeLeagueWinRT PROPERTIES
VS_WINRT_COMPONENT TRUE
VS_GLOBAL_ROOTNAMESPACE "JusticeLeagueWinRT"
OUTPUT_NAME "JusticeLeagueWinRT"
)