20

On macOS, how do I create an Xcode project from existing code? I want to try some features of Xcode like 'profile'.

I currently use Clion for my cmake project, it is also in git repo. I simply want to import it from Xcode but it's not that easy I guess. Here some info about project and IDE:

  • It is just a console app written in C++ and cmake project
  • It is also on git repo
  • Xcode Version 8.0 (8A218a)
  • OS El Capitan 10.11.6
Cœur
  • 37,241
  • 25
  • 195
  • 267
Richard
  • 335
  • 1
  • 2
  • 9
  • 1
    I've been writing cross-compiled code on OSX and Linux for 3 years. I would recommend that you invest a little money - visit the jetbrains.com website and buy a licence for Clion and AppCode. These tools are brilliant. XCode is garbage. It can't even refactor Apple's own language, swift, let alone c++. The Xcode lead was recently fired. One Clion licence gives you an excellent CMake-based IDE that works on windows, linux and OSX. It even works over XWindows. – Richard Hodges Jan 24 '17 at 17:17
  • 1
    @RichardHodges [AppCode is discontinued as of December 14, 2022](https://blog.jetbrains.com/appcode/2022/12/appcode-2022-3-release-and-end-of-sales-and-support/) – Cœur Feb 01 '23 at 09:37

2 Answers2

42

Cmake has a generator for Xcode. Try:

cmake -G Xcode <dir of CMakeLists.txt>
Cœur
  • 37,241
  • 25
  • 195
  • 267
Waldson Patricio
  • 1,489
  • 13
  • 17
  • 1
    small remark: all generated content (including Project.xcodeproj) by this command will be created in the folder you'r shell is in. cd to dir of CMakeLists.txt and use `.` as argument... – Ivan Temchenko Apr 14 '19 at 20:48
  • 1
    @IvanTemchenko or better: `cmake -G Xcode -B build` where `build` is the name of the folder for all generated content – Cœur Feb 01 '23 at 09:47
-3

What I do:

"File"->"New"->"Project..."

Select command line tool:

enter image description here

Fill in some stuff if you'd like:

enter image description here

Run the dummy project:

enter image description here

Click on the project file and "Add files to" your project:

enter image description here

Browse to your pile of source. Expand the options. I tend use "added folders" as "Create Groups":

enter image description here

Go through and prune out the files you don't want:

enter image description here

Build. Likely you'll need to keep removing files or adding them till your project works.

  • 7
    You are basically just ignoring the cmake project. You would have to keep your manually-created xcode project up-to-date with the cmake project everytime something changes in the CmakeLists.txt. That's literally the reason why cmake is used in the first place. – athos Apr 03 '19 at 06:41