Jerry B
Jerry B

Reputation: 453

How to add a CLI target to a GUI project in XCode 3.2.6

I started working on a project to build an OS X app, and one component is a file scanner & parser. So far, that's the main part I've been working on. In order to test it, before I delve in to the meat of the project, I'd like to build a command line program that I can feed strings and/or files, to make sure it's actually scanning & parsing correctly. So I used Add New Target and selected Cocoa Shell Tool. In that target, I added the relevant files for the parser, made sure it was linking 'Cocoa.framework'...

And I get 11,000+ errors when it tries to pre-compile '/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/AppKit.framework/Headers/AppKit.h'.

Am I totally on the wrong track on how to add a command line target?

(Before anybody asks, no, XCode 4 isn't an option. This machine isn't leaving 10.6.8 any time soon.)

Upvotes: 0

Views: 70

Answers (1)

Jerry B
Jerry B

Reputation: 453

Well, I never found out how to do that, but I found a reasonable substitute.

In the Info.plist, create an LSEnvironment dictionary, containing some key/value pair. I used 'GUILaunch=true'. This environment variable will only be available when launched by launchd, not when directly launched in a shell.

In main.m:

int main(int argc, char *argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSDictionary *env = [[NSProcessInfo processInfo] environment];
    NSString *gui = [env objectForKey:@"GUI_Launch"];
    if ((gui!=nil) && [gui isEqual:@"true"]) {
        [env release];
        [gui release];
        return NSApplicationMain(argc, (const char **) argv);
    } else {
        [env release];
        [gui release];
        return main2(argc, argv);
    }
    [pool release];
}

Now, the standard GUI bits are called, or main2 is called, based on how it's launched.

Upvotes: 1

Related Questions