Why isn't Swift compiler flag being set? - xcode

I want some code to only be executed in a release build, but the code does not get executed when the scheme is configured to use the release configuration.
What am I missing?
I have the following in my app delegate's didFinishLaunchingWithOptions method:
#if RELEASE
Countly.sharedInstance().startOnCloudWithAppKey(appKey)
Crittercism.enableWithAppID(appID)
NSLog("crash logging enabled")
#endif
The target build settings look like this:
And the scheme is configured to use the Release configuration when I run the app:

You will need to set the preprocessor flags explicitly in the "Swift Compiler - Custom Flags" section, "Other Swift Flags" line.
Please check-
In absence of preprocessor macros, is there a way to define practical scheme specific flags at project level in Xcode project

It looks like the Swift compiler ignores -D flags that assign a specific value. If you use -DDEBUG and -DRELEASE, it seems to work.

now you need to set
Active Compilation Conditions
under Swift Compiler - Custom Flags
e.g.
Active Compilation Conditions DEV
you can check
#if DEV
print("DEV mode")
#else
print("PROD")
#endif

Related

Step to pass "-std=c++11" flag in gdb regression test-suite setup

I am trying to run GDB testsuite with "-std=c++11" flag for the subtest case under "gdb.cp" folder or for the CPP related test-cases.
Currently I am performing it using DejaGnu directive "dg-options" in CPP test-case like :
// { dg-options "-std=c++11" }
But I am not confirm whether this is right way or not. Because if I check the gdb.log file, I am not seeing "-std=c++11" flag passed at compile time.
The easiest way would be, from the top-level build directory, to run the tests like:
make check-gdb RUNTESTFLAGS="CXX_FOR_TARGET='g++ --std=c++11' gdb.cp/*.exp"
GDB also supports CFLAGS_FOR_TARGET which can be set in the same way, despite being called CFLAGS these flags are appended for any compile, so you'll start to see warnings/errors about --std=c++11 being an invalid option for C tests, etc.
A final option that might be of interest would be creating a whole new DeJaGNU board file which would override the compiler flags, however, I couldn't get this working so quickly, so your mileage may vary.
You can find more information about running the tests here: https://sourceware.org/gdb/wiki/TestingGDB

CMake Xcode generator - add capability "hardened runtime"

Problem is quite simple. I have multi platform project (Windows/Mac OS).
Now in case of Mac OS I need to enable "Hardened runtime" in capabilities section of my bundle (it is launchd daemon).
I wish my Xcode project is generated by cmake (I don't want to maintain multiple project files).
If I can overcome this problem by modifying build process (for example by adding some flags to xcodebuidl command) it should be fine, but I prefer when everything is defined in CMakeLists.txt files.
You can use the property XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME, which is a boolean.
Set that property on your macOS target, e.g.
set_property(TARGET target PROPERTY XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME YES)
Or if you provide more properties for the target it might look like this:
set_target_properties(target PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME "yourTargetName"
MACOSX_RPATH TRUE
MACOSX_FRAMEWORK_IDENTIFIER com.host.target
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "#loader_path/Libraries"
RESOURCE "${RESOURCE_FILES}"
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME YES
)

Including INAppStoreWindow in existing project

How can I include INAppStoreWindow into my existing xcode project?
When I simply include this:
#import "INAppStoreWindow.h"
I will get a error, that it is not existing. I read that I have to compile with linker flag
-fobjc-arc
But, I don't know how to get that working.
Can someone please help me?
For any questions, please let me know
you need to set compiler flags to -fno-objc-arc for INAppStoreWindow.m file. To Set this go to Target->Build Phases->Compile Sources->INAppStoreWindow.m and set the compiler flags to -fno-objc-arc.
To set A linker flag you should go to your project file
Target->Build Phases->Compile Sources->INAppStoreWindow.m
(See image Below)
Double click the INAppStoreWindow.m file
and add the -fno-objc-arc. flag to it.
(See image below)

Is there a macro that Xcode automatically sets in debug builds?

So I can write code like this:
#ifdef [whatever]
// do stuff that will never show up in the production version
#endif
Nothing useful per default, but you can set a DEBUG macro for debug builds in the "Preprocessor Macros" of the targets build settings and then do:
#ifdef DEBUG
// do stuff
#endif
If you want to automate that, edit the project templates in "/Developer/Library/Xcode/Project Templates":
Find the XCBuildConfiguration section(s) for which name = Debug;.
In the buildSettings add DEBUG to the list for GCC_PREPROCESSOR_DEFINITIONS if it exists
Otherwise add GCC_PREPROCESSOR_DEFINITIONS = (DEBUG); to the buildSettings
For per-user customizations and to avoid them being overwritten, see this question.
If you can assume that debug builds always use gcc -O0 (this is normally the case, but there may be odd exceptions where someone has changed the optimisation level for debug builds) then you can do this:
#if __OPTIMIZE__
// ... non-debug stuff ...
#else
// ... debug stuff ...
#endif

Xcode/GCC predefined macro for target name?

I was wondering if there is an Xcode or GCC preprocessor symbol for the target name of the application.
For example if I'm building an application called "MonkeyChicken", is there a preprocessor symbol such that
printf( __TARGET_NAME__ )
outputs:
MonkeyChicken
I don't believe there is any built-in (gcc has no idea what you're building when you compile a file), but you can always create one using GCC_PREPROCESSOR_DEFINITIONS in an xcconfig file (you are using xcconfig, right?) Something like this should work as you indicate above:
GCC_PREPROCESSOR_DEFINITIONS = __TARGET_NAME__=\"$(PRODUCT_NAME)\"

Resources