0

I took over a project that has several build schemes: demo, release, debug and production. throughout the code.. there are several preprocessor macro if statements ie

#ifdef DEMO
static NSString *const URL_SMART_TAXI      = @"http://demo.theapp.com";
#elif  PRODUCTION
static NSString *const URL_SMART_TAXI      = @"http://prod.theapp.com";
#elif  DEBUG
static NSString *const URL_SMART_TAXI      = @"http://localhost:8000";
#else
static NSString *const URL_SMART_TAXI      = @"http://dev.theapp.com";
#endif

for some reason, this always works when i'm building with a demo scheme or a production one.. but it just doesn't work for debug (whenever I change the scheme and run for debug.. it always skips the debug and goes for the wild card option)..

I looked all over the project and I don't see any special treatment given for demo or production that's not given for debug..

If I run grep -nri %environment% * this is the result:

grep -nri production *
project.pbxproj:2767:               84380FEB1705D3E40085487D /* Production */ = { 
project.pbxproj:2797:                       name = Production;
project.pbxproj:2799:               84380FEC1705D3E40085487D /* Production */ = { 
project.pbxproj:2832:                                       "-DPRODUCTION",
project.pbxproj:2846:                       name = Production;
project.pbxproj:3013:                               84380FEB1705D3E40085487D /* Production */, 
project.pbxproj:3024:                               84380FEC1705D3E40085487D /* Production */, 
xcshareddata/xcschemes/theApp.xcscheme:47:      buildConfiguration = "Production"

grep -nri demo *
project.pbxproj:2685:               6314932116E4F7D000B351CA /* Demo */ = { 
project.pbxproj:2715:                       name = Demo;
project.pbxproj:2717:               6314932216E4F7D000B351CA /* Demo */ = { 
project.pbxproj:2751:                                       "-DDEMO",
project.pbxproj:2765:                       name = Demo;
project.pbxproj:3012:                               6314932116E4F7D000B351CA /* Demo */, 
project.pbxproj:3023:                               6314932216E4F7D000B351CA /* Demo */, 
xcshareddata/xcschemes/theApp.xcscheme:87:      buildConfiguration = "Demo"

grep -nri debug *
project.pbxproj:2848:               847D410E168CBD3700CE1B96 /* Debug */ = { 
project.pbxproj:2863:                                       "DEBUG=1",
project.pbxproj:2879:                       name = Debug;
project.pbxproj:2912:               847D4111168CBD3700CE1B96 /* Debug */ = { 
project.pbxproj:2955:                       name = Debug;
project.pbxproj:2972:                                       "DEBUG=1",
project.pbxproj:3010:                               847D410E168CBD3700CE1B96 /* Debug */, 
project.pbxproj:3021:                               847D4111168CBD3700CE1B96 /* Debug */, 
xcshareddata/xcschemes/theApp.xcscheme:26:      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
xcshareddata/xcschemes/theApp.xcscheme:27:      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
xcshareddata/xcschemes/theApp.xcscheme:29:      buildConfiguration = "Debug">
xcshareddata/xcschemes/theApp.xcscheme:43:      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
xcshareddata/xcschemes/theApp.xcscheme:44:      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
xcshareddata/xcschemes/theApp.xcscheme:49:      debugDocumentVersioning = "YES"
xcshareddata/xcschemes/theApp.xcscheme:72:      debugDocumentVersioning = "YES">
xcshareddata/xcschemes/theApp.xcscheme:84:      buildConfiguration = "Debug">

any ideas?

update: + relevant parts of build settings

enter image description here enter image description here enter image description here

abbood
  • 23,101
  • 16
  • 132
  • 246
  • You're missing the `-D` before `DEBUG=1` - it should be `-DDEBUG=1`. – Paul R May 13 '14 at 10:22
  • what's the purpose of that extra `D`? – abbood May 13 '14 at 10:23
  • It's a command line switch to define a macro - you have it for PRODUCTION and DEMO, but it's missing in the case of DEBUG. – Paul R May 13 '14 at 10:24
  • @PaulR but DEBUG=1 is defined in my `release` scheme.. which i never use.. should I just put -DNS_BLOCK_ASSERTIONS=1 -DDEBUG under other C/C++ flags? but [DNS_BLOCK_ASSERTIONS](http://stackoverflow.com/a/2752581/766570) doesn't seem to be relevant to what i'm trying to do – abbood May 13 '14 at 10:36
  • oh my bad.. those two are totally separate things.. – abbood May 13 '14 at 10:38

1 Answers1

2

This is because you're doing "#elif", which is NOT the same thing as "#elifdef" (if such a thing exists).

You should define PRODUCTION, DEBUG and DEMO all at the same time, but set only one to "1" and the others to "0".

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • then why does it work just fine when i use `#elif` for production? – abbood May 13 '14 at 10:22
  • @Michael is right that you shouldn't mix `#ifdef` with `#elif`, but I think the real problem in your case is the missing `-D` before `DEBUG=1`. – Paul R May 13 '14 at 10:23
  • because you are likely doing "`#define PRODUCTION 1`" and since DEBUG isn't defined at all when you are building for production, it matches as if you were doing "`#if PRODUCTION`". Which would become "`#if 1`" while compiling. – Michael Dautermann May 13 '14 at 10:23
  • @PaulR ok guys I see a lot of value in what you're both saying.. but i'm still a bit confused.. I updated my question with the relevant parts of my build settings.. does it make my situation more clear? – abbood May 13 '14 at 10:32
  • @MichaelDautermann couldn't find a `define PRODUCTION 1` anywhere in the code. – abbood May 13 '14 at 10:34
  • 1
    if this were my project, I *might* add in "`DEMO=0 PRODUCTION=0`" to that preprocessor macro line that says "`DEBUG=1`". And then change "`#ifdef`" to "`#if`". Makes sense now? – Michael Dautermann May 13 '14 at 10:34