I have some image files I need to add to an Xcode project. I need the files to be included in the Copy Bundle Resources build phase. I also need Type to be set to Data to avoid any compression or processing by Xcode.
Is this possible with premake5?
You can use a filter to select the files and then do an embed action
filter "files:%{prj.name}/Res/**"
buildaction "Embed"
This example adds all of the files in the Res folder to the Copy Bundle Resources. Although XCode won't show them in the Copy Bundle Resources list they should still show up in the target directory after you build and run the project.
https://github.com/premake/premake-core/wiki/buildaction
Related
In my Xcode project I have a custom build phase which runs a script and downloads some images for use by the app. What I want to do is to automatically add those image to the project during the build. Right now, I have to build once (which downloads the files), and then manually add those files to the project. It works as long as the file names don't change. Instead, I'd like to add all the files in a specific directory to the project.
I've tried setting the Output Files value, as suggested here, like this:
$(PROJECT_DIR)/$(PROJECT_NAME)/External Assets/*
but it doesn't work. Any idea if this can be done?
Create a directory with the .bundle extension. Add this bundle to your app's resources. When the project builds, it will automatically copy every file in the bundle, even if they are changed or added after you first add the bundle to the project.
I'm building an iOS app that frequently loads JSON configuration files at runtime.
However, the files are very generous with comments and indenting.
How can I tell XCode to copy minified versions of the files to the bundle during build?
You just need to add a build phase to your target. Here is an example, my build script that converts a multimarkdown file to an HTML file.
# Create the HTML file from the Markdown File
/usr/local/bin/multimarkdown --process-html --output="${SCRIPT_OUTPUT_FILE_0}" --to=html "${SCRIPT_INPUT_FILE_0}"
# Publish the Help Text and Image to Dropbox
if [ -d ~/Dropbox/Public/DCWS-Help-Text ]; then
rsync -t "${SRCROOT}/DC Wire Sizer/en.lproj/"* ~/Dropbox/Public/DCWS-Help-Text/
fi
I create the file in the source directory but added it to my git ignore file. It is a build product and not in source control, but you need to make sure it is in your project and part of the target, so it gets copied into the bundle. Also make sure your build script runs before your copy bundle phase.
I am building an Xcode project from console over ssh (I can use only xcodebuild command), but there are no schemes in the project (user forgot to make schemes shared). xcodebuild allows to pass "archive" parameter only if building scheme (-scheme), but that is not an option for me.
So the question is: is it possible to create archive using only target?
I investigated .xcarchive directory, it contains Info.plist file (which contains information about application), dSYMs directory (containing myapp.dSYM) and Products/Applications (containing myapp.app) directory. I also noted that the file size of binary in .xcarchive's .app is 2 times smaller than in .app that is in Release directory. I guess it is because of code signage.
Can I simply copy files from Release directory (.app and .dSYM) to .xcarchive and create Info.plist there to create archive? Or are there any other steps that I must take?
yes, archives are only folders you can make yourself.
look at ANY archive and try to replicate the folder structure. (changing the appname as required)
Background: I'm using CMake to configure a project that builds a combination of libraries and applications. Each application uses resource files such as images and text files that are unique to that application. Xcode understands the concept of resource files and can correctly copy them into the application bundle. If I were creating a project with exactly one application, there would be no problem: I can use CMake's set_source_files_properties(... PROPERTIES MACOSX_PACKAGE_LOCATION Resources) to tell Xcode to put the files into the bundle's Resources directory, such that a later call to [[NSBundle mainBundle] pathForResource:...] will correctly find them. (The pathForResource method searches the "Resources" directory by default.) The files also appear in the Resources group within the Xcode project.
Question: The problem appears when I include multiple applications in the CMake project. Each project needs to copy its own, distinct resource files into its own bundle's Resources directory. Therefore each application needs a distinct Resource group in Xcode in which to hold these files and from which to copy them. Yet these distinct directories must all be named "Resources." Ideally, each application-specific folder within Xcode would have its own unique "Resources" subdirectory with all of its needed resources. What actually happens is that the project has a single, shared Resources directory into which all the resource files are collected, and the project-specific "Resources" subdirectory contains only that application's info.plist file. Because all applications' resources are tossed into the same group, and because name collisions can occur (two projects with distinct files that have the same name), project bundles don't get the correct resource files.
Has anyone found a way to use CMake to setup an Xcode project that supports multiple applications with distinct resources? Or some other workaround?
My solution works for me but maybe this is not satisfying for you.
What I do is a simple copy files post build step where I copy my resources directly into the built Target.app.
The problem with my approach is that the files don't show up in the Xcode project.
Here is how I do it :
I override the ADD_EXECUTABLE macro. Inside, it evaluates the resource variable ${target}_RESOURCES.
So in my CMakeLists.txt for my target I collect some directories and resource files and store them as list in my target depending resource variable.
The following custom command is in my macro (could be anywhere, actually):
ADD_CUSTOM_COMMAND( TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -DFILES_LIST="${${target}_RESOURCES}" -DDESTINATION="\${TARGET_BUILD_DIR}/\${FULL_PRODUCT_NAME}" -DEXCLUDE_EXT=".svn .git CVS .DS_Store" -P ${ROOT_DIR}/cmake/scripts/copyFiles.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMENT "Copying resource files and directories to iOS App Bundle..." )
It calls my copy files script (Maybe there is a better way to add that custom build step):
SEPARATE_ARGUMENTS( FILES_LIST )
FOREACH( ENTRY ${FILES_LIST} )
MESSAGE( "copying: ${ENTRY} to ${DESTINATION}" )
FILE( COPY ${ENTRY} DESTINATION ${DESTINATION} PATTERN "${EXCLUDE_EXT}" EXCLUDE )
ENDFOREACH( ENTRY )
It works for me. I don't really care if the resources show up in the XCode project.
But I still would like to know.
Are there are any problems or issues when not having the files in Xcode?
Could someone explain the difference between the Copy Bundle Resources phase of Xcode and a Copy Files phase? When would I use "Copy Files"?
Copy Bundle Resources phase copies files that you want to be available in your bundle (.app). On the other hand Copy Files phase copies files to other (standard) locations accessible from your application (for example to /Library/Fonts) giving you also the option to copy them only when installing. You can also see relevant documentation here
Xcode Copy Files vs Copy Bundle Resources
Copy Files - Copies files from a project to an external specified location.
It is useful, for example, when you are creating an Objective-C Static Library where you should expose .modulemap[About] or/and umbrella.h[About] files
Copy Bundle Resources - Copies files that support your source code into internal structure. If you want to make sure the files you added will get copied to the application bundle
It is useful, when you are creating an app where you can add images and other resources
Vocablurary