13

I am trying to open an existing C++ open-source library in Xcode to publish it with my own modification/additions. The library is Tesseract-OCR, which does not include a .xcodeproj file.

Since Xcode can function as an IDE, is it possible to open a bunch of files as a single project in Xcode? Is there an easy way to produce an Xcode project?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jes Chergui
  • 1,318
  • 1
  • 22
  • 33

5 Answers5

15

There are several ways you could do it, depending on the level of IDE integration you want. There's no direct way of importing a Makefile-based project into Xcode. You can create a project that builds via the Makefile, but you wouldn't get many of the benefits of using an IDE, since the editor features such as word completion rely on Xcode being able to parse the files in the project. You will be able to use the debugger though. To do this, create a new project and add a custom target with a script build phase that just calls down to Makefile.

If however the project you're building compiles very easily, ie without requiring a lot of macros to be set up, include paths, etc, then it may be simple to just create an empty project and merely add all source files to it. I've used this method extensively for building boost libraries. If this is a configure && make type project then you will probably have to run the configure step first, and ensure any top level config.h files are included in the project.

If the project has a complex makefile then it is likely to be an involved task to create a useful Xcode project

the_mandrill
  • 29,792
  • 6
  • 64
  • 93
6

To create an Xcode project from an existing cmake project, you can run cmake -G Xcode. It produces some folders and files apart from the project file, so it might be better to create a folder for it first. For example:

mkdir -p build/xcode
cd build/xcode
cmake -G Xcode ../..
Elgar de Groot
  • 171
  • 1
  • 4
5

I realise you asked explicitly for Xcode, but in case you were actually trying to solve the problem of "I have existing C++ code which builds and runs fine from the command line, and I'd like to code and debug it in an IDE, what should I do?" my firm recommendation would be to avoid Xcode and go for Eclipse.

The reason is that as far as I can tell, Xcode has no way of ingesting the command line build environment and effectively requires you to recreate the make process inside Xcode from scratch. Fine for tiny projects, but anything with more than a few source files and it quickly becomes painful. Whereas in Eclipse everything is built around Makefiles. So in my case I got to the "step through code with working code completion" in Eclipse a lot quicker vs. never in Xcode. This of course could be because I'm an Xcode noob, but my 2c.

Stephan
  • 99
  • 1
  • 9
1

Xcode is a useable IDE for library creation.

Of course a good first step is to see if the one source code will build on its own with configure scripts that are included.

If not, it becomes a question of how many libraries you need to link in.

There are resources online (or at least there used to be) for using Xcode (or perhaps it's forerunner Product builder) for porting Unix projects to Mac.

Good tutorial at: http://www.macresearch.org/tutorial-introducing-xcode-30-organizer

Another good reference is Darwin Ports.

As for doing this on your own. You can build c++ based libraries in XCode. People do that every day. You can even use one of the Xcode templates to get you started.

However, library dev requires more experience with Xcode then say a simple Cocoa "Hello World" app.

The remaining questions will be assuring that the source code's dependencies are already built into the Mac's SDK. (Don't hold your breath for linking to MFC)

It's a general question... So it's a general answer.

xaxxon
  • 19,189
  • 5
  • 50
  • 80
Dru Freeman
  • 1,766
  • 3
  • 19
  • 41
-1

In Xcode8,there is "Xcode->file->add files to...",then choose your files.If you want to add several files at a time,press "Cmd" when you are choosing.