2

Does Xcode support exporting a build configuration (compiler & linker options and flags) to a Makefile? Or is there a 3rd party implementation available for such task?

We do most of our (native code) development with Xcode, but we need to also compile it against Windows / Linux libraries. Generally we have valid build configurations in Xcode, and we manually edit Makefiles before committing code modifications. This process is error prone and creates undesired differences between development environment and our build system.

Automatically exporting the build configurations to Makefiles would greatly simplify our flow.

Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
Elist
  • 5,313
  • 3
  • 35
  • 73

1 Answers1

1

I think your answer is xcodebuild -showBuildSettings

$ xcodebuild -showBuildSettings
Build settings for action build and target YourApp:
ACTION = build
AD_HOC_CODE_SIGNING_ALLOWED = NO
ALTERNATE_GROUP = staff
ALTERNATE_MODE = u+w,go-w,a+rX
ALTERNATE_OWNER = Stanislaw
...

You can combine it with normal options like -scheme, -configuration, -target etc.

Also people try to work with so called .xcconfig files when it comes about injection of some custom flags. This path can get you somewhere but is not a super convenient way of doing a cross-platform development because they work only on Mac. See this for example: Using xcconfig files for your XCode Project.

Another indirect way of getting the information is to get a dump of all compilation commands from Xcode, see this answer: How can I get all the compile commands from Xcode?.

As far as I know, Xcode is not really friendly when it comes to dealing with all of its flags separately.


Another option to consider is to switch from Makefiles to CMake. CMake is not perfect but so far it seems to be the best tool out there: it can generate Xcode projects and it can help you a lot in creating your libraries targeted for different platforms.

Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
  • I would really recommend you to look into CMake. Most likely it will solve your problems. This: `Generally we have valid build configurations in Xcode, and we manually edit Makefiles before committing code modifications.` does not sound good :) – Stanislav Pankevich Jun 08 '17 at 08:34
  • `xcodebuild -showBuildSettings` is a good start, but there are still lots of important things missing, such as compiled files, libraries etc. – Elist Jun 08 '17 at 13:39
  • I have updated my answer with two more indirect options: using xcconfig files and getting compile commands but one more time: I do recommend you to look into CMake. It is the absolute default for cross-platform development these days. – Stanislav Pankevich Jun 08 '17 at 13:55
  • Thanks, that is an interesting material. I will try to come up with an overall solution with it. Migrating to CMake sounds like too much work, and will work the other way around (I prefer maintaining the projects from xcode). – Elist Jun 09 '17 at 07:42