Xcode: Enable CMake to create folder references
If CMake were able to add folder references in an Xcode project, I wouldn't have to add icons to the Xcode project after generation in order to submit an iOS app to the App Store. It would also be handy to add directories of assets so they can be easily packaged in the app.
A folder reference is shown as a blue folder in Xcode and indicates a reference to an actual folder in the file system. It's needed to properly add all the required icons into the app. I'm able to use source_group to add yellow folders, but those are only for organizational purposes and won't add the icons.
I've found that the location of the icon folder within a given target's folder doesn't seem to matter. Aside from dragging the icon folder into Xcode, the icon files must be added to target_sources and that same icon file list must be referenced in the RESOURCE target property. Based on that, I think the folder reference could be added in CMake with a new FOLDER_REFERENCE target property whose value is the folder being referenced.
From here on out, I'll use the following project to make the discussion more concrete:
The Rectangles target is my sample iOS app:
Here's my environment
- CMake 3.15.2
- Conan 1.18.1
- Xcode 10.3 (10G8)
- macOS 10.14.4
Here are the steps I currently go through to add the folder reference:
- git clone https://gitlab.com/ssrobins/sdl2-example.git
- cd sdl2-example
- Open the generated project in Xcode
- In Finder, double-click on the Rectangles folder to show the Rectangles.xcassets folder
- Drag the Rectangles.xcassets folder into the Rectangles folder in the Xcode project
- It should pop up a window indicating that it's creating a folder reference for target Rectangles. Click Finish.
If you go to Product > Scheme > Choose Scheme, it'll now show the red icon next to the Rectangles target, indicating a successful icon install.
So, in the example above, the proposed new CMake code would be:
set_target_properties(Rectangles PROPERTIES FOLDER_REFERENCE "Rectangles.xcassets" )
Removing these manual steps would make it much easier to fully automate the iOS app build, package, and submission process. I'm happy to help with any additional design and implementation of this feature!
Hope to see some CMake people at CppCon again this year :)