📜 ⬆️ ⬇️

Using Xcode with GNU Make

I think no one will argue that writing code in the IDE is much more convenient than, say, in vim or some other “just editor”. Here and syntax highlighting (in fairness it should be noted that it is in almost all editors) and autocompletion and close connection with the debugger. Sometimes documentation. Well, in general, a lot of different nice things.
But historically, each IDE stores the description of the build parameters in its own way. Often in a completely unsightly form. This does not create problems if the development is carried out on the target platform. And if the code is cross-platform? And on other platforms (even if only on one of them) the IDE is missing?
Unpleasant

So I ran into such a problem: I have a Mac in my workplace (I use XCode as IDE), and I write network code that should work on a large range of equipment, starting with the iPhone and ending with Sony PS.
XCode is a pretty good IDE. There are no serious complaints about it. Well, except for the strange format of the "project".

But it turns out that everything is not as bad as it seems at first glance. And after a few unobvious, but very simple actions, we can teach Xcode to GNU Make. At the same time, we get both a handy IDE, and all the power of make. And there is make on such platforms that I haven’t even heard of.
Getting started.

')
Create a project template

Launch XCode and in the “File” menu select “New Project”.
Next, when choosing “template”, select “Other” -> “External Build System”
As usual, enter the name of the project.

At this stage we have a project template. Good. We continue.

Create a new "target"

In the "Project" menu, select the item "New Target".
In the window that appears, select "Other" -> "External Target". We press the button “Next” and get a new window, where we enter the name target`a (Enter any - it has nothing to do with the file names, etc. This only indicates how the target will be named in XCode)
Double click on the new target and in the “Directory” field specify the directory in which the Makefile is located.
Next, in the “Progect” menu, using the “Set Active Target” item, we make our new target active. You can delete the old target with a clear conscience.

Add the source code to the project

Now we add the source code to the project in the usual way.
Without copying! Let it remain in its place.

Specify the path to the executable file

In the “Project” menu, select the “New Custom Executable” item and in the “Executable Path” column specify the path to the directory where Make will build your project. Well, add the name of the file at the end.
Those. You must enter the path to the resulting executable file.
Click "Finish" and can use.

Done!


Further actions are no different from the usual use of Xcode.

This “recipe” was rechecked for XCode versions 3.2.3 and 3.2.4. I do not deliberately provide screenshots, since the algorithm works for much older versions of the IDE, but the interface is somewhat different.

Use on health!

Source: https://habr.com/ru/post/108065/


All Articles