creating an XCode project with existing code - xcode

I'm in the process of porting a Linux application to Mac. I have different files with the source code that can get compiled and linked using the standard Makefile.
I'm going to be porting that code to Mac and continue writing code in C (sorry, no obj-c). Is there a way to create a project on XCode, add the existing code so I can use XCode and the IDE, compile and debug the code and generate Mac Makefiles?
Thanks for the help

New Project -> Other -> External Build System
(in new project)
Expand "Targets"
select the target the template created
press return
edit the target settings:
by default, it uses /usr/bin/make for invocation. if you want to use some other build system, then you'll have more to configure.
for a Makefile, you will need to set the 'Directory' field of the build settings window to the directory which contains the appropriate makefile to build.
note that you'll lose some integration when using a makefile.
you can regain some of that by adding the sources to the project (drag and drop), and not associating them with a target.
to improve navigation and code completion, you may want to create a second (dummy) target (such as a static library) so the ide parses your programs. you would then add the sources to the dummy static library, and set the makefile as a 'dependency' of the static library (so it gets built, and so it gets built first).

The Apple Developer docs have a section on porting makefile based projects into XCode.
"Porting UNIX/Linux Applications to OS X"
This subsection is most relevant: "Building makefile projects with XCode"
https://developer.apple.com/library/content/documentation/Porting/Conceptual/PortingUnix/preparing/preparing.html#//apple_ref/doc/uid/TP40002849-BBCJABGC

You can build using your existing makefiles and create a wrapper project with a custom target with a 'Run Script' build phase that just calls down to your makefile. This means that you'll also be able to use the debugger, but you probably won't get the full benefit of the editor with autocompletion etc.

To import C code into Xcode:
start xcode
new project
pick something like Standard Tool. Should read c command line tool.
drag you file or files onto main project window. This is the first window that comes up when you create a new project. My project name is xaBitHoist. I dropped the files on xaBitHoist > src.
just build. Seems to default to main.c
to change start program or add argues Project > New Project Executable.
the online help for xcode is good.
Good luck.
Robert

Related

Xcode 13 and Linux Makefile

I searched and it seems all the answers are from are from many years ago. I'm working on a command line tool for linux/Mac that currently uses a Makefile. I wanted to use the Xcode debugger, so I tried to build an Xcode project, but I'm having some final difficulties.
I created a new project of type command line tool with external build target in the project directory. The default was to use /usr/bin/make. It ended up in a subdirectory, and based on several older web resources, I moved the project file up to the folder with the makefile. I added the source files in the folder to the project and right now I can edit and build from Xcode without difficulty.
The issue is that the final executable ends up in a subfolder called bin, and I can't seem to discover how to tell Xcode that that is the final executable. All of the resources I've found talk about adding a custom executable to the target from the project menu, but that menu no longer exists. Searching project help doesn't seem to point to any setting for the executable produced by an external build process. The closest build setting I could find was PROJECT_NAME, but changing that didn't seem to help.
Thanks.
Found an answer on another site. Edit the info tab in the scheme to identify the binary.

Where does Xcode save preprocessor macro settings

I am working on a project that was created using cmake. (It's a project that is built for lots of different platforms, including Linux Mac OS, and now iOS.)
The cmake process creates an Xcode project which I then am modifying manually.
One of the things the project contains is dozens of preprocessor macros that drive #ifdefs in the code.
The cmake tool only defines these macros for debug builds. I need to build a release version so I can profile the project. however, the release build fails because of missing preprocessor macros, which cause the #ifdef/#ifndef compiler directives to be set wrong.
I'd really rather not manually enter 35 preprocessor settings, especially since the Xcode editor displays this awkward popup with + and - buttons to add/remove one at a time, and when I'm editing release symbols, I can't see the debug symbols, and copy/paste doesn't work.
What I really want to do is find the internal file in the xcode project that sets these macros, copy it out of the debug settings, and either paste it into the release version, or at the very least, manually enter one macro at a time into the release version by copying it from a textfile containing the macros that were defined in the debug version.
Can somebody tell me where the debug and release preprocessor macros are saved in the Xcode project file hierarchy so I can go read the raw file and possibly modify it?
In your project.pbxproj, search for GCC_PREPROCESSOR_DEFINITIONS. That should be a list of the macros. It should be pretty easy to copy and paste the list from one configuration to the other.

How can I change my BB10 project to use a makefile?

I recently created a new Blackberry project Momentics, and it runs fine from the IDE, but I need to be able to build it from the command line using a Makefile. I ran make in Terminal, but received an error because the makefile does not exist.
I checked the sample apps that I've been looking at, and they all have makefiles. I found some sources that say you can pick whether you use a managed build or a makefile when you create the project, but I found no such option in the latest version of Momentics (2.1). I tried changing this setting in the project properties, but the Builder Settings under C/C++ Build are all greyed out.
How can I change my BB10 project to use a makefile? If that isn't possible, how can I require a new project to use a makefile instead of a managed build?
It turns out that the option to use a makefile is unintentionally hidden in OSX. When you create a Blackberry Core Native project, the Build Settings screen will look like this:
I viewed the same screen on Windows, and the option that I wanted was right below language. I then tried again in OSX, and found out that you can scroll this screen to show the "Build" option.
I also discovered that creating the project as a Blackberry Cascades project doesn't give you this option at all, but will always use a makefile to build.
I also tried converting my original project from using managed build to using makefile. This appeared to be possible from the File > Import option. I tried importing my project as BlackBerry > Existing Code as BlackBerry C/C++ Makefile Project and as C/C++ > Existing Code as Makefile Project, but neither option actually converted my project to a makefile project. Unfortunately, because of this, the best solution to convert the project seems to be starting a new project with the desired setting and copying the files and settings from the old project.

Managing Static Library project as a module like Framework on iOS project in Xcode4

Many people including me trying to make a kind of Static Library framework for iOS to archive some kind of modularity. Framework is best way to do this, but it doesn't provided by Apple, and workarounds don't work well.
https://github.com/kstenerud/iOS-Universal-Framework/tree/master/Fake%20Framework/Templates
Fake framework cannot be referenced from linking tab in Build Phases.
Real framework needs modification of system setting. And still not work smoothly on every parts.
Problem is static library need header files, and it's impossible to reference header files on project at another location on different project without some script. And script breaks IDE's file management abstraction.
How can I use static library project like a convenient module manner? (just dragging project into another project to complete embedding)
I've since updated the template to do away with the script target. It now builds the universal framework from your regular target, so you can include it in workspaces or as a project dependency.
With a real framework target, you can just add it to "Link Binary With Libraries", and it will show up fine.
With a fake framework, Xcode doesn't recognize the target type, so you need to add the link command manually. For example, assuming your framework is called Foo:
Expand the "Products" group of your framework project, then drag "Foo.framework" into the "Link Binary With Libraries" build phase of your app target.
In your app target, edit "Other Linker Flags" in the build settings and add: "-framework Foo"
Framework template link for anyone not sure what we're talking about: https://github.com/kstenerud/iOS-Universal-Framework
Solution.
Goto Project or Target's Build Settings.
Find Public Headers Folder Path. (definition name = PUBLIC_HEADERS_FOLDER_PATH)
Set it as YourLibrary.framework/Headers. I have used ${PRODUCT_NAME}.framework/Headers for automatic syncing with project name.
Goto Build Phases and find Copy Headers step.
Move all required headers to Public pane.
Now all header files will be formed like Framework and copied with product binary. IDE will copy all of them as a unit into some temporary folder like app's build folder. So referencing app project can use the headers automatically.
This is a trick. The created directory structure is not real framework. Because it doesn't contain any binary. However we don't need real framework to archive just this functionality. IDE works with frameworks without any binary. And I don't want to hack IDE without documentation about internal structure.
This works well, however you'll experience some problem when you Archive. This happens because Xcode4 behaves specially when Archiving. Here's workaround.
For each embedded library project, SKIP_INSTALL = YES in target build settings.
For final product project, FRAMEWORK_SEARCH_PATHS = "${OBJROOT}/UninstalledProducts". Take care about this setting should be set only for Release build mode.
Now it'll be archived well.
At the case of cross platform library, there can be many projects for many platforms. But sometime Xcode will show some product as red color even it compiled successfully.
This is a bug of Xcode. IDE display depends SDKROOT of Project build setting. So if you set the SDKROOT differently on Target, it won't work. You can check the the product will become black color after changing the SDKROOT of the Project build setting. See this Open Radar entry for details.
http://openradar.appspot.com/9636211
If you wish to fix this bug, please report this to Apple's Radar. Duplicated bugs will make attention of Apple. Just copy & paste my report :)
I found this : http://db-in.com/blog/2011/05/creating-universal-framework-to-iphone-ios/
It seems to work.

How to create a new XCode project from an existing c/c++ code space

How to create a new XCode project from an existing c/c++ code space?
What type of project I should pick from XCode project template?
Thank you.
Assuming the existing code has a build system like Make or CMake etc., you probably want to use the "External Build System" template under "Other" in the projects pane. If you want to incorporate the existing code into a new application/framework/etc., create a template for the type of product you want to eventually build, then add a "Run Script" build phase to call your external build system.
MacResearch.org has a tutorial on using the Xcode Organizer to build external targets that you may also find useful.

Resources