From 7f53068940ffd324a186fea98dc3d892795fa7f6 Mon Sep 17 00:00:00 2001
From: Bartosz Kosiorek <bartosz.kosiorek@tomtom.com>
Date: Wed, 18 Nov 2015 16:40:58 +0100
Subject: [PATCH] Create flat directory structure for resources in iOS Bundles.

A typical iOS application bundle (also Framework Bundle
contains the application executable and any resources used by
the application (for instance, the application icon, other images,
and localized content) in the top-level bundle directory.
The same rule is applicable for Framework Bundles, bug: 15848
---
 Help/prop_tgt/RESOURCE.rst   | 67 ++++++++++++++++++++++++++++++++++++++------
 Source/cmGeneratorTarget.cxx |  6 +++-
 2 files changed, 64 insertions(+), 9 deletions(-)

diff --git a/Help/prop_tgt/RESOURCE.rst b/Help/prop_tgt/RESOURCE.rst
index 1e9921d..8272997 100644
--- a/Help/prop_tgt/RESOURCE.rst
+++ b/Help/prop_tgt/RESOURCE.rst
@@ -1,11 +1,62 @@
 RESOURCE
 --------
 
-Specify resource files in a FRAMEWORK shared library target.
-
-Shared library targets marked with the FRAMEWORK property generate
-frameworks on OS X and normal shared libraries on other platforms.
-This property may be set to a list of files to be placed in the
-Resources directory inside the framework folder.  On non-Apple
-platforms these files may be installed using the RESOURCE option to
-the install(TARGETS) command.
+Specify resource files in a :prop_tgt:`FRAMEWORK` or :prop_tgt:`BUNDLE`.
+
+Target marked with the :prop_tgt:`FRAMEWORK` or :prop_tgt:`BUNDLE` property
+generate framework or application bundle (both OS X and iOS is supported)
+or normal shared libraries on other platforms.
+This property may be set to a list of files to be placed in the corresponding  directory (eg. ``Resources`` directory for OS X) inside the bundle.  On non-Apple
+platforms these files may be installed using the ``RESOURCE`` option to
+the ``install(TARGETS)`` command.
+
+Following example of Application Bundle:
+::
+  add_executable(ExecutableTarget
+    addDemo.c
+    resourcefile.txt
+    appresourcedir/appres.txt
+  )
+
+  target_link_libraries(ExecutableTarget heymath mul)
+
+  set(RESOURCE_FILES
+    resourcefile.txt
+    appresourcedir/appres.txt
+  )
+
+  set_target_properties(ExecutableTarget PROPERTIES
+    MACOSX_BUNDLE TRUE
+    MACOSX_FRAMEWORK_IDENTIFIER org.cmake.ExecutableTarget
+    RESOURCE "${RESOURCE_FILES}"
+  )
+::
+
+will produce flat structure for iOS systems:
+::
+  ExecutableTarget.app
+    appres.txt
+    ExecutableTarget
+    Info.plist
+    resourcefile.txt
+::
+
+For OS X systems it will produce following directory structure:
+::
+  ExecutableTarget.app/
+    Contents
+      Info.plist
+      MacOS
+        ExecutableTarget
+      Resources
+        appres.txt
+        resourcefile.txt
+::
+
+For Linux, such cmake script produce following files:
+::
+  ExecutableTarget
+  Resources
+    appres.txt
+    resourcefile.txt
+::
\ No newline at end of file
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 40afc0e..4b9fc9d 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -3751,7 +3751,11 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const
       if(cmSourceFile* sf = this->Makefile->GetSource(*it))
         {
         SourceFileFlags& flags = this->SourceFlagsMap[sf];
-        flags.MacFolder = "Resources";
+        flags.MacFolder = "";
+        if(!this->Makefile->PlatformIsAppleIos())
+          {
+          flags.MacFolder = "Resources";
+          }
         flags.Type = cmGeneratorTarget::SourceFileTypeResource;
         }
       }
-- 
2.4.9 (Apple Git-60)

