From ca05063c5dae73bcb5b69b2931e86db258a028db Mon Sep 17 00:00:00 2001
From: Gilles Khouzam <gillesk@microsoft.com>
Date: Tue, 2 Dec 2014 13:32:45 -0800
Subject: [PATCH] Added VS_DEPLOYMENT_LOCATION property to specify where to put
 files that are part of the package

Here's a sample:
set_property(SOURCE ${ASSET_FILES} PROPERTY VS_DEPLOYMENT_LOCATION "assets")
---
 Help/manual/cmake-properties.7.rst                        |  1 +
 Help/prop_sf/VS_DEPLOYMENT_LOCATION.rst                   |  8 ++++++++
 Help/release/3.1.0.rst                                    |  4 ++++
 Source/cmVisualStudio10TargetGenerator.cxx                | 15 +++++++++++++++
 Tests/VSWinStorePhone/CMakeLists.txt                      |  7 ++++++-
 .../cmake/Package_vc11.store.appxmanifest.in              |  6 +++---
 .../cmake/Package_vc12.store.appxmanifest.in              |  8 ++++----
 .../VSWinStorePhone/cmake/Package_vc12.wp.appxmanifest.in |  8 ++++----
 8 files changed, 45 insertions(+), 12 deletions(-)
 create mode 100644 Help/prop_sf/VS_DEPLOYMENT_LOCATION.rst

diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index bf456f5..b107e5a 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -291,6 +291,7 @@ Properties on Source Files
    /prop_sf/OBJECT_OUTPUTS
    /prop_sf/SYMBOLIC
    /prop_sf/VS_DEPLOYMENT_CONTENT
+   /prop_sf/VS_DEPLOYMENT_LOCATION
    /prop_sf/VS_SHADER_TYPE
    /prop_sf/WRAP_EXCLUDE
    /prop_sf/XCODE_EXPLICIT_FILE_TYPE
diff --git a/Help/prop_sf/VS_DEPLOYMENT_LOCATION.rst b/Help/prop_sf/VS_DEPLOYMENT_LOCATION.rst
new file mode 100644
index 0000000..08b9215
--- /dev/null
+++ b/Help/prop_sf/VS_DEPLOYMENT_LOCATION.rst
@@ -0,0 +1,8 @@
+VS_DEPLOYMENT_LOCATION
+---------------------
+
+Specifies the deployment location for a content source file with a Windows 
+Phone or Windows Store application when built with a Visual Studio generator.
+This property is only applicable when using :prop_sf:`VS_DEPLOYMENT_CONTENT`.
+The value represent the path relative to the app package and applies to all
+configurations.
diff --git a/Help/release/3.1.0.rst b/Help/release/3.1.0.rst
index d6921c4..5110782 100644
--- a/Help/release/3.1.0.rst
+++ b/Help/release/3.1.0.rst
@@ -165,6 +165,10 @@ Properties
   to tell the Visual Studio generators to mark content for deployment
   in Windows Phone and Windows Store projects.
 
+* A :prop_sf:`VS_DEPLOYMENT_LOCATION` source file property was added
+  to tell the Visual Studio generators the relative location of content
+  marked for deployment in Windows Phone and Windows Store projects.
+
 * The :prop_tgt:`VS_WINRT_COMPONENT` target property was created to
   tell Visual Studio generators to compile a shared library as a
   Windows Runtime (WinRT) component.
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index f591fc8..3ae69c8 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -1247,6 +1247,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
     }
 
   std::string deployContent;
+  std::string deployLocation;
   if(this->GlobalGenerator->TargetsWindowsPhone() ||
      this->GlobalGenerator->TargetsWindowsStore())
     {
@@ -1255,6 +1256,12 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
       {
       toolHasSettings = true;
       deployContent = content;
+
+      const char* location = sf->GetProperty("VS_DEPLOYMENT_LOCATION");
+      if(location && *location)
+        {
+        deployLocation = location;
+        }
       }
     }
 
@@ -1269,6 +1276,14 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
       cmGeneratorExpression ge;
       cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
         ge.Parse(deployContent);
+      // Deployment location cannot be set on a configuration basis
+      if(!deployLocation.empty())
+        {
+        this->WriteString("<Link>", 3);
+        (*this->BuildFileStream) << deployLocation
+                                 << "\\%(FileName)%(Extension)";
+        this->WriteString("</Link>\n", 0);
+        }
       for(size_t i = 0; i != configs->size(); ++i)
         {
         if(0 == strcmp(cge->Evaluate(this->Makefile, (*configs)[i]), "1"))
diff --git a/Tests/VSWinStorePhone/CMakeLists.txt b/Tests/VSWinStorePhone/CMakeLists.txt
index 0041c75..d3c705e 100644
--- a/Tests/VSWinStorePhone/CMakeLists.txt
+++ b/Tests/VSWinStorePhone/CMakeLists.txt
@@ -86,6 +86,9 @@ if (WINDOWS_PHONE8)
 elseif (NOT "${PLATFORM}" STREQUAL "DESKTOP")
   set(CONTENT_FILES ${CONTENT_FILES}
     ${CMAKE_CURRENT_BINARY_DIR}/${APP_MANIFEST_NAME}
+    )
+
+    set(ASSET_FILES ${ASSET_FILES}
     Direct3DApp1/Assets/Logo.png
     Direct3DApp1/Assets/SmallLogo.png
     Direct3DApp1/Assets/SplashScreen.png
@@ -94,10 +97,12 @@ elseif (NOT "${PLATFORM}" STREQUAL "DESKTOP")
 endif()
 
 set(RESOURCE_FILES
-  ${CONTENT_FILES} ${DEBUG_CONTENT_FILES} ${RELEASE_CONTENT_FILES}
+  ${CONTENT_FILES} ${DEBUG_CONTENT_FILES} ${RELEASE_CONTENT_FILES} ${ASSET_FILES}
   Direct3DApp1/Direct3DApp1_TemporaryKey.pfx)
 
 set_property(SOURCE ${CONTENT_FILES} PROPERTY VS_DEPLOYMENT_CONTENT 1)
+set_property(SOURCE ${ASSET_FILES} PROPERTY VS_DEPLOYMENT_CONTENT 1)
+set_property(SOURCE ${ASSET_FILES} PROPERTY VS_DEPLOYMENT_LOCATION "Assets")
 set_property(SOURCE ${DEBUG_CONTENT_FILES} PROPERTY VS_DEPLOYMENT_CONTENT $<CONFIG:Debug>)
 set_property(SOURCE ${RELEASE_CONTENT_FILES} PROPERTY
   VS_DEPLOYMENT_CONTENT $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>)
diff --git a/Tests/VSWinStorePhone/cmake/Package_vc11.store.appxmanifest.in b/Tests/VSWinStorePhone/cmake/Package_vc11.store.appxmanifest.in
index d3cb21f..68172fa 100644
--- a/Tests/VSWinStorePhone/cmake/Package_vc11.store.appxmanifest.in
+++ b/Tests/VSWinStorePhone/cmake/Package_vc11.store.appxmanifest.in
@@ -4,7 +4,7 @@
   <Properties>
     <DisplayName>@SHORT_NAME@</DisplayName>
     <PublisherDisplayName>mgong</PublisherDisplayName>
-    <Logo>StoreLogo.png</Logo>
+    <Logo>Assets/StoreLogo.png</Logo>
   </Properties>
   <Prerequisites>
     <OSMinVersion>6.2.1</OSMinVersion>
@@ -15,9 +15,9 @@
   </Resources>
   <Applications>
     <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="@SHORT_NAME@.App">
-      <VisualElements DisplayName="@SHORT_NAME@" Description="@SHORT_NAME@" BackgroundColor="#336699" ForegroundText="light" Logo="Logo.png" SmallLogo="SmallLogo.png">
+      <VisualElements DisplayName="@SHORT_NAME@" Description="@SHORT_NAME@" BackgroundColor="#336699" ForegroundText="light" Logo="Assets/Logo.png" SmallLogo="Assets/SmallLogo.png">
         <DefaultTile ShowName="allLogos" ShortName="@SHORT_NAME@" />
-        <SplashScreen Image="SplashScreen.png" />
+        <SplashScreen Image="Assets/SplashScreen.png" />
       </VisualElements>
     </Application>
   </Applications>
diff --git a/Tests/VSWinStorePhone/cmake/Package_vc12.store.appxmanifest.in b/Tests/VSWinStorePhone/cmake/Package_vc12.store.appxmanifest.in
index 495f18e..08205f5 100644
--- a/Tests/VSWinStorePhone/cmake/Package_vc12.store.appxmanifest.in
+++ b/Tests/VSWinStorePhone/cmake/Package_vc12.store.appxmanifest.in
@@ -4,7 +4,7 @@
   <Properties>
     <DisplayName>@SHORT_NAME@</DisplayName>
     <PublisherDisplayName>mgong</PublisherDisplayName>
-    <Logo>StoreLogo.png</Logo>
+    <Logo>Assets/StoreLogo.png</Logo>
   </Properties>
   <Prerequisites>
     <OSMinVersion>6.3</OSMinVersion>
@@ -20,14 +20,14 @@
         Description="@SHORT_NAME@"
         BackgroundColor="#336699"
         ForegroundText="light"
-        Square150x150Logo="Logo.png"
-        Square30x30Logo="SmallLogo.png">
+        Square150x150Logo="Assets/Logo.png"
+        Square30x30Logo="Assets/SmallLogo.png">
         <m2:DefaultTile ShortName="@SHORT_NAME@">
           <m2:ShowNameOnTiles>
             <m2:ShowOn Tile="square150x150Logo" />
           </m2:ShowNameOnTiles>
         </m2:DefaultTile>
-        <m2:SplashScreen Image="SplashScreen.png" />
+        <m2:SplashScreen Image="Assets/SplashScreen.png" />
       </m2:VisualElements>
     </Application>
   </Applications>
diff --git a/Tests/VSWinStorePhone/cmake/Package_vc12.wp.appxmanifest.in b/Tests/VSWinStorePhone/cmake/Package_vc12.wp.appxmanifest.in
index 2d4d389..d47d43c 100644
--- a/Tests/VSWinStorePhone/cmake/Package_vc12.wp.appxmanifest.in
+++ b/Tests/VSWinStorePhone/cmake/Package_vc12.wp.appxmanifest.in
@@ -6,7 +6,7 @@
   <Properties>
     <DisplayName>@SHORT_NAME@</DisplayName>
     <PublisherDisplayName>mgong</PublisherDisplayName>
-    <Logo>StoreLogo.png</Logo>
+    <Logo>Assets/StoreLogo.png</Logo>
   </Properties>
   <Prerequisites>
     <OSMinVersion>6.3.1</OSMinVersion>
@@ -22,14 +22,14 @@
         Description="@SHORT_NAME@"
         BackgroundColor="#336699"
         ForegroundText="light"
-        Square150x150Logo="Logo.png"
-        Square30x30Logo="SmallLogo.png">
+        Square150x150Logo="Assets/Logo.png"
+        Square30x30Logo="Assets/SmallLogo.png">
         <m2:DefaultTile ShortName="@SHORT_NAME@">
           <m2:ShowNameOnTiles>
             <m2:ShowOn Tile="square150x150Logo" />
           </m2:ShowNameOnTiles>
         </m2:DefaultTile>
-        <m2:SplashScreen Image="SplashScreen.png" />
+        <m2:SplashScreen Image="Assets/SplashScreen.png" />
       </m2:VisualElements>
     </Application>
   </Applications>
-- 
1.9.4.msysgit.1

