Simply i have two frameworks from a payment provider, they provide Debug and Release frameworks, to be used for different environments.
I was trying to configure/find out on the web of a way that i can configure the import of both of them in one scheme, and depending on the Build Configuration it will switch between Debug and Release framework.
I played with Framework Search path for example Debug to have debug url to framework, and the same for Release to link to release framework url to file.
Im looking for something more usable and easy such as run script, or stying away from manual import for each build configuration.
Note: Framework has the same name, as well as the framework is build with objective-c without single header import.
You can try below approach,
Create a new folder "Frameworks" in the project directory where .xcodeproj exists.
Place release framework in /Frameworks/Release/arm64/
Place debug framework in /Frameworks/Debug/x86_64/
Paste below script in Build Phases -> Run Script:
cp -r "$PROJECT_DIR/Frameworks/$CONFIGURATION/$ARCHS" "$PROJECT_DIR/"
rm -dfR <Name of the framework> && \
cp -pRP "$ARCHS" <Name of the frameowrk> && \
rm -rf "$ARCHS"
not sure if it suits your needs, but you can try
#if DEBUG
import debugFramework
#else
import releaseFramework
#endif
Related
I have one ESP-IDF application and two hardware boards. I use a preprocessor definition to control which hardware board version to build. For now, I'm modifying the config in the sdkconfig file via menuconfig. But I would like to build both versions at once from a script, or build only one specific config without the manual process of menuconfig.
I have a header that looks like this, and works when HW_VER is set correctly:
#if HW_VER == 2
#define BTN_GPIO 9
#elif HW_VER == 3
#define BTN_GPIO 10
#endif
And from the a script I would like to build each by selecting a value for HW_VER, for example:
idf.py build -DHW_VER=2
idf.py build -DHW_VER=3
The idf.py build command runs cmake and ninja. I'm new to cmake, so perhaps there is a natural way to do this?
I would also like to build release and debug builds, turn on/off memory debugging etc. from the command line.
I've tried idf.py build -DHW_VER=2 but I've learned that these vars are only sent to cmake and not to the preprocessor. The HW_VER macro remains undefined.
Using add_definitions() in my CMakeLists.txt can set HW_VER, but doesn't help me make different builds from the same files.
Using a config variable like CONFIG_HW_VER in the sdkconfig works to control builds using menuconfig but I don't see a way to automate this.
I've considered modifying the configuration variable, CONFIG_HW_VER in the sdkconfig file programmatically, but this file is under source control, and it is auto generated by menuconfig, so that doesn't seem wise.
Similarly I can modify the CMakeLists.txt file programmatically, but that file is also under source control, and isn't a trivial format.
I use two ways to feed custom configurations into an ESP IDF project.
Firstly, the light weight stuff like preprocessor definitions from the environment are quite simple. You have to configure CMakeLists.txt file (the one in project root) to pass variable values from environment into the build process. For example, to create something equivalent to preprocessor definitions -DMY_NUMBER=123 and -DMY_STRING="abc" add this somewhere before the "project" line:
add_compile_definitions(MY_NUMBER=$ENV{MY_NUMBER})
add_compile_definitions(MY_STRING=\"$ENV{MY_STRING}\")
...
project(myproject)
Assuming you're working in Bash, build with:
$ MY_NUMBER=123 MY_STRING="abc" idf.py build
or (for a slightly more "sticky" enviroment):
$ export MY_NUMBER=123 MY_STRING="abc"
$ idf.py build
You can use cmake to add more advanced logic, e.g. setting default values in case the environment doesn't set anything.
Secondly, the more powerful configuration tool for ESP IDF is the menuconfig target and sdkconfig file. As you've already noticed, playing with sdkconfig directly is not so easy. In my projects I consider this a generated temporary file and I never commit it to git. Instead I delete it. When sdkconfig is missing, idf.py will take file sdkconfig.defaults, copy it into sdkconfig and work with this. That is your best mechanism for supporting different hardware configurations - no sdkconfig and instead different variants of sdkconfig.defaults for each hardware you wish to support.
As an example, assume you have two different HW versions described in sdkconfig.defaults.hw_ver1 and sdkconfig.defaults.hw_ver2 and you wish to build for HW ver2 configuration:
$ rm sdkconfig && cp sdkconfig.defaults.hw_ver2 sdkconfig.defaults
$ idf.py reconfigure
Now you can build for this configuration like you usually would:
$ idf.py build
When you wish to build for the other FW configuration, re-execute the previous commands with sdkconfig.defaults.hw_ver1
All this is rather thoroughly documented in the Build System documentation, so feel free to dig in.
I created a qt application which can be build by cmake. My application uses some ros2 service so I need to build it with ros. For that I need to put my code under ros2_ws/src/. I want to avoid this thing. I want to build by application from any folder ( without putting under ros2_wc) with ament tool. How can I do it ?
If you want to do that, you need to build ROS2 as usual, and source the following script:
. install/local_setup.bash
Then you can call your build command using ament from the directory you want.
cd <dir>
ament build --force-cmake-configure ...
For those who are using the new ros2 build tool: colcon
You can keep your own ~/ros2_ws, and put the QT application to another ~/ros2_overlay_ws.
For example, if your new QT application depends on some service or msg located in the original ~/ros2_ws, you could go to ~/ros2_ws and run colcon build.
After compile finished, please remember to import and re-index your packages by the following command: source ~/ros2_ws/install/setup.bash. This will re-index your ros2 packages at current terminal.
Now go to ~/ros2_overlay_ws/ and put your QT application to ~/ros2_overlay_ws/src and then run colcon build. colcon will find your indexed package and add them to your dependency.
I just installed from pkg the SDK 3.7 for Facebook.
I see that I need to put there a value for FacebookAppId. However I have 2 apps: one for testing and one for production.
Since I need to support variables for Debug and Release, I am using an Environment file which determines the value based on the configuration value. (Debug or Release)
How can I "tell" the SDK to use the relevant one for each release type, without changing it manually when building it?
I didn't check in the source code. Just the compiled one.
Is there a way to do it?
You can use the Preprocessor macros over here..
How to use it :
Go to Build settings of your project.
Search "Preprocessor macros". Here define your macros like for eg FBDebugAPPID for debug moed & FBReleaseAPPID for release mode.
FBSettings class used to override the default facebook AppId.
Then after add below code in your delegate method..
#if defined(FBDebugAPPID)
**Use your debug app id**
[FBSettings setDefaultAppID:#"DEBUGAPPId"]
#elif defined(FBReleaseAPPID)
**Use your release app id**
[FBSettings setDefaultAppID:#"RELEASEAPPId"]
#endif
Hope it resolve your problem..
You can change you enviornment.plist variables by adding a run script build phase
To add a Run Script Build Phase in Xcode
Select your application target in your project, then select "Build Phases".
In the menu bar, click "Editor", select "Add Build Phase", and then click on "Add Run Script Build Phase".
You should now see a Run Script section in the middle of your Build Phase options, as shown above.
Inside the body of the Run Script Build Phase, paste in the script.
#!/bin/bash
if [ "${CONFIGURATION}" = "Release" ]; then
/usr/libexec/PlistBuddy -c "Set :FacebookAppID 321" "$INFOPLIST_FILE"
else
/usr/libexec/PlistBuddy -c "Set :FacebookAppID 321" "$INFOPLIST_FILE"
fi
Here's a simpler approach,
Recent Xcode project templates already have a DEBUG=1 macro defined for the Debug build configuration.
You can use it in combination with #ifdef
#ifdef DEBUG
#define FACEBOOK_APP_ID #"FB_DEVELOPMENT_ID"
#else
#define FACEBOOK_APP_ID #"FB_PRODUCTION_ID"
#endif
I want to include the GNU Scientific Library (GSL) in my Cocoa app so that the user needs not installing it locally first. Like most GNU packages, it's the standard configure / make / make install routine. But this won't work:
./configure --prefix ~/libgsl
make
make install
Since the prefix is local to my computer. And neither is this:
./configure --prefix (path to build folder)/libgsl
make
make install
What I want is essentially the GSL being contained entirely in my application, and I can call its functions without the users downloading anything else.
I'm rather new to Xcode 4 and the build system for Clang/GCC, having coming over from .NET. Any help is much appreciated.
Assuming there is not a framework-style build of the library, the way this is typically done when bundling with 3rd party libraries is to build the package as normal, install it in /usr/local, and configure your project to include and link from there. Building is the easy part though.
The tricky part is bundling up the .app correctly. You need to add a custom build stage (after the others) which first copies all the dependent .dylib files into your app bundle's Frameworks folder (using the environment variables to help; see Xcode docs). Then you need to use install_name_tool to get the app binary to look in the framework dir (as the embedded soname still thinks it is in /usr/local). This part is very fiddly and not well documented.
I've just extracted this from a working project where I use GSL. Just add this as an extra build phase in your XCode project as a Custom Script:
# Framework folder for Example.app
FRAMEWORKS_DIR=${TARGET_BUILD_DIR}/Example.app/Contents/Frameworks
# Create path if it doesn't exsit
mkdir -p ${FRAMEWORKS_DIR}
# Find the original linked path for libgsl
GSLLIB=`otool -L ${TARGET_BUILD_DIR}/Example.app/Contents/MacOS/Example | grep libgsl | cut -d" " -f1`
GSLPATH=`dirname $GSLLIB`
# Copy the dylibs into your app
cp /usr/local/lib/lib{gsl,gslcblas}.0.dylib ${FRAMEWORKS_DIR}
# Update embedded paths
install_name_tool \
-change ${GSLPATH}/libgsl.0.dylib \
#executable_path/../Frameworks/libgsl.0.dylib \
${TARGET_BUILD_DIR}/Example.app/Contents/MacOS/Example
This should work with a simple substitution of your app name.
This is basically the same as what you need to do to build a standalone Qt app, so the docs here are very relevant:
Deploying Qt on the Mac
It is worth reading up on bundles, frameworks and packaging. For example:
Mac OS X Framework Reference
This post is also relevant:
How do I link libraries in Xcode 4?
Note that GSL is published under the GPL, so your app would need to be similarly published in order to respect the license. Shipping the source is necessary, but not sufficient for compliance.
When building the project from command line using mvn clean install everything builds without any issues.
When running some tests that use precompiled C libraries from IntelliJ, tests fail with java.lang.UnsatisfiedLinkError
I may be completely off here, but does IntelliJ not see the .so file? Is so, how can it be added please?
Shared library fails to load with UnsatisfiedLinkError if:
it's not in the working directory configured in the test run configuration.
it's not in PATH environment (on Mac Terminal and GUI apps have different environment, see this answer). Run IDEA from the Terminal open -a /Applications/IntelliJ\ IDEA\ 12.app/ to make environment the same.
it's not in the location specified using -Djava.library.path VM option.
.so depends on some other library that is not found for any of the 1-3 reasons (or the dependency of that dependency is not found, etc).