Preprocessor Directives to separate targets in xcode - ios

I have 2 targets on my project one production and one stage with different configurations.
I want in the code to be able to say
#if target == production
NSLog(#"production");
#elif target == stage
NSLog(#"stage");
#endif
Can someone please tell me how can I do that?
Thank you,
~Sonic555gr

You can define some Preprocessor Macros for each Target, like this...
And then you can do something like this:
#ifdef PRODUCTION
//some Code
#elif STAGE
//some other Code
#else
//more Code^^
#endif
But be carefull if you need it in Debug- and/or in Release-Build, you have to declare it there.

Related

How to compile eigen with VS2019, /std:c++latest and /Zc:__cplusplus

I'm trying to compile eigen 3.3.9 fron the github mirror with VS2019, /std:c++latest and /Zc:__cplusplus
What i get is a
eigen\Eigen\src\Core\util\Meta.h(320,25): error C2039: 'result_of': is not a member of 'std'
because EIGEN_HAS_STD_RESULT_OF is defined. This get's determined here:
#ifndef EIGEN_HAS_STD_RESULT_OF
#if EIGEN_MAX_CPP_VER>=11 && ((__has_feature(cxx_lambdas) || (defined(__cplusplus) && __cplusplus >= 201103L)))
#define EIGEN_HAS_STD_RESULT_OF 1
#else
#define EIGEN_HAS_STD_RESULT_OF 0
#endif
#endif
From what i can read, std::result_of is removed in C++20 which is not reflected in the check above.
Am i doing something wrong? Is there an easy way to compile eigen with VS, C++20 and a __cplusplus define which reflects the actual standard version without having to manually set all the defines myself or patching Macros.h?

Use define between systemverilog and DPI-C

In systemverilog sv_define.vh
`define A_MODULE_ENABLE
//`define B_MODULE_ENABLE
In C c_define.h
#define A_MODULE_ENABLE
//#define B_MODULE_ENABLE
Since syntax for "define" is different between systemverilog and C.
If I want to config ENABLE, I have to modify those two files, that would sometimes be troublesome. How can I just define them in a single file and include it ? Thanks a lot.
My imagination: my top.sv and top.c would include the same file: c_sy_define.vh
The content would be:
__SV__
`define A_MODULE_ENABLE
//`define B_MODULE_ENABLE
__C__
#define A_MODULE_ENABLE
//#define B_MODULE_ENABLE
Yeap. This will probably work. Never try it though.
#ifndef COMPILE_IN_C
`define A_MODULE_ENABLE
#endif
`ifndef COMPILE_IN_SV
#define A_MODULE_ENABLE
`endif
Wen you compile the header file, make sure you add "-define COMPILE_IN_SV" in ncvlog (say you use Cadence), and add "-DCOMPILE_IN_C" in gcc.

IOS/Xcode: Suppress NSLog Statements for Release in 2018

Because NSLog statements slow down apps, it seems advisable to remove them prior to release. A number of older answers on SO going back to 2010 suggest putting some code in the pch file such as:
#ifndef DEBUG
#define NSLog(...);
#endif
However, Xcode no longer automatically creates a pch file. I gather it is possible to manually create a pch file but this seems like a bit of a kludge. Is manually creating a pch file and adding the above code to it still the recommended way to comment out NSLog statements prior to release or is there a more modern approach?
All the old answers I found (including adding a PCH file) didn't work for Swift. Here's what finally worked for me:
Define the DEBUG flag by adding "-D DEBUG" to "Other Swift Flags" in the build settings.
Add the following global code (I just put it in a file named Globals.swift):
#if !DEBUG
public func NSLog(_ format: String, _ args: CVarArg...) {
}
public func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {
}
#endif
It is still possible to create a pre-compiled header, however this is discouraged, at least by default. To do this, edit the build settings for your target, and define a path to a Prefix Header.
Use a Logging Library
Perhaps you can use a logging library, like CocoaLumberJack, or here is a very simple one, that nonetheless works well.

Using Pre-processor Macro,how to change file name for Development, staging and production Environment?

Problem statement:- I am using third party library, which need to have config.plist(name must be same), Config.plist have several key-value pairs, for production,Dev and stating environment, values for key does change.
Right now i need to manually change file Name, like if i need to run app in production environment, i do change file name ConfigPROD.plist into Config.plist,
for Staging i do change file name from ConfigDev.plist into Config.plist.
Need Solution like:- can i change, file content using preprocessor macro, like
#if isProductionBuild == 1
#define kBaseURL #"https://api.base.com/bart/"
#define kEnvironmnet #"PROD"
***//copy ConfigPROD.plist file content into Config.plist***
#elif isStageBuild == 1
#define kBaseURL #"https://api-stage.base.com/bart/"
#define kEnvironmnet #"stg"
*//copy ConfigSTG.plist file content into Config.plist*
#else
#define kBaseURL #"https://api-dev.base.com/bart/"
#define kEnvironmnet #"dev"
*//copy ConfigDEV.plist file content into Config.plist*
#endif
pleae see if we do have feature like "copy ConfigDEV.plist file content into Config.plist"
Note:- This file copy operation should get completed before third party library start using Config.plist.
You don't need a preprocessor macro, you need a Run Script build phase that gets executed first. See Running a Script While Building a Product for an introduction. Just create a Bash script that looks at $CONFIGURATION (which will be Debug or Release or any other configuration name you have) and then renames one or the other file. Something like:
mv ./Config.plist ./Config.plist.orig
if [[ 'Release' == ${CONFIGURATION} ]]; then
cp ./Config.PROD.plist ./Config.plist
else
cp ./Config.DEV.plist ./Config.plist
To easily handle this, add all 3 files (Config.plist, Config.DEV.plist and Config.PROD.plist) to Xcode, but only the first one should be added to the target (check the box in the right side panel). You can have default settings in this file, it will be overwritten anyway.
If you're using git or something similar, you can add another run script phase at the end of your build to restore the original Config.plist to hide your changes from git.

Test selected target with preprocessors macro

I want to test the selected Target with preprocessors macro. Anybody have an idea ?
#if TARGET1
#myVar #"aValue"
#elsif TARGET2
#myVar #"anotherValue"
#endif
Thank you by advance !
See please 'Build Settings' tab in xcode project for a specific target and 'Preprocessor macros' option. You can define a macros there and use it in code like:
#ifdef DEBUG
#myVar #"aValue"
#else
#myVar #"anotherValue"
#endif

Resources