As we known, we can set target membership for a certain file/bundle in right navigator of xcode.
But now I want to set target membership in a certain configuration. So how can I set target for a file/bundle in xcconfig file?
Many Thanks!
You could attach a build phase that:
runs before you copy bundles phase.
It would detect whether the config is Debug vs Release using ${CONFIGURATION}
and then copy the file into a location/name where it would then get picked up by the copy files phase.
Related
To access the resource file namefile from a program:
I ostensibly just need to check the box "target membership" to identify it as a resource file:
but this box is disabled.
What am I missing?
The helloworld target in your project is configured as a command-line tool (the square black icon that looks like a Terminal indicates this). Those compile to a single, standalone file thus Xcode cannot embed a resource file with it (which is why it's disabled).
You need to build a "Cocoa Application" target if you want to be able to include resource files. You can start a new project using the Cocoa Application template or manually add a target to your current project. You'll probably find it easier to start with a new project.
Add resource files to a command line tool
Add the file to the "Copy Files" section of your project's Build Phases:
Make sure to set Destination to "Resources", clear Subpath, and untick Copy only when installing.
Then whenever you build, Xcode will copy the file into your app's build directory, right next to the executable:
That's a screenshot of the ~/Library/Developer/Xcode/DerivedData/[your project]/Build/Products/Debug folder.
This method also works when you archive your app.
Note: if you want the file to be in some subfolder relative to the executable, e.g. res/images/, set the Subpath to that path.
I have a custom build rule for a file type, which I setup according to this blog post. The build rule is working fine and my file is compiled.
But if I add a new file of this type to the project and I select the targets, the file is currently added to the "Copy Bundle Resources" phase. Instead, I'd like to have it added to the "Compile Sources" phase automatically (if I don't do this, the build rule won't kick in).
Is there a flag or something I can set so Xcode recognizes my files as "source files"?
using Xcode 3.2.5 on 10.6.6 (10J521) and now 10J537.
I have an Xcode project containing 1 Target: "MyApp". It builds and runs successfully.
As well as source and resource files, the Target contains a "Copy Files" build phase which copies "Sparkle.framework" in. The framework is in the same directory as the project.
I want to duplicate this Target. Steps taken:
Did "Clean all Targets".
Right-clicked on the "MyApp" Target within Xcode, and then chose "Duplicate".
Renamed the duplicated target to "MyAppTarget2".
Selected "MyAppTarget2" as the Active Target from the popup menu in the top-left.
Did "Build".
The problem:
error: Sparkle/Sparkle.h: No such file or directory
At the line:
#import <Sparkle/Sparkle.h> // In MyAppDelegate.mm
This is puzzling! Further info:
Each Build step appears to have been replicated in the duplicated Target, including the "Copy Files" phase.
The Sparkle.framework itself exists in the project's folder.
In the "Link Binaries with Library" phase of both "MyApp" and "MyAppTarget2", I am linking to the Sparkle.framework at the above location. A "Get Info" on the linked binary reports that it is a member of both Targets.
If I right-click on the Sparkle.framework file within the "Copy Files" build phase of the duplicated Target, and select "Reveal in Finder", then the correct Sparkle.framework file is shown. The required file exists at Sparkle.framework/Headers/Sparkle.h
If I switch back to the original "MyApp" target, it builds and runs successfully.
Am I doing something obviously wrong here? Thanks.
[EDIT - SOLVED]
I had a look at the Build settings for each supposedly-identical Target.
Under "Framework Search Paths", the first Target had this:
$(inherited) "$(SRCROOT)"
But the duplicated Target had this path:
$(inherited) \"$(SRCROOT)\"
It appears that Xcode incorrectly escaped the path during the duplication process. Ouch.
I know you have already solved this issue yourself, but I thought I'd share my fix for this issue (as it has happened to me several times). I've always been able to get rid of this error by deleting the file in question and just recreating it. I have no idea why this works... but, as is often the case with XCode, there seems to be some Voodoo at work.
Build Phase copy is still broken in 12.5! It does only copy a few of the source targets build phases. What a crap IDE.
I have been trying to build a code that has dependencies with other header files that are not in the project directory. I added the paths to these header files in both HEADER_PATH and USER_PATH. However, I still see error while building. It says that the file is not found. I verified that the file exist in the path added to the header search path in project settings.
How do I make sure that all my header files referenced in the project is included and the paths are being picked by Xcode during compilation?
I tried copying all the files to the project with no luck. This is the first time iam using Xcode, so its kind of frustrating. Iam a linux guy and comfortable with make files. Is there a Make file for xcode which i can modify to include the header file directories.
You might want to check the order of your source files in your target's build phases to ensure that your dependencies are compiled before your source files that reference them.
Select your project in the Project Navigator.
Select your target.
Click on the Build Phases tab.
Click on Compile Sources to expand the section.
Drag the dependencies to the top of the list.
Are you sure you spelled the header file name correctly ? Is the case correct ? Did you use user quotes "" rather than system quotes <> ?
Assuming you've checked all the obvious things such as the above then one other thing to try is to quit Xcode, delete the "build" folder in your project directory, and try again - sometimes the build folder gets in a pickle internally.
I am developing an application which uses .js files stored in the Resources/javascript folder of my application bundle. In my Xcode 2.5 project I have created a folder reference (not a group) to my javascript folder, which automatically added the folder to the Copy Bundle Resources build phase.
The problem I have is when I modify my .js files, I need to clean my project then re-build it for the modified .js files to get copied into my application bundle when building. This is very time consuming since I re-build the whole project just to get an updated .js file in my app bundle.
Could someone tell me how to get Xcode to always copy specific files in the build phase?
Thanks in advance!
You could right- or control-click the file (in the project file list) and click "Touch" before building (manual) or add a script build phase to the target that calls "touch myfile.js" and place it before your Copy Files build phase (automatic).
Add a new Copy Files Build Task to your target.
Right Click (Control Click) on the target, Add -> New Build Phase -> New Copy Files Build Phase.
In the Dialog select the destination that you want the files to be copied.
This will create the phase under the target. Drag the files you wish to copy to the phase.
There's an excellent walkthrough here of a build phase script which automates the 'touch' and saves the manual step of specifying each file you want included.